File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -188,12 +188,15 @@ public function setPrefix($prefix = '')
188188 *
189189 * @param string $query Contains a user-provided query.
190190 * @param array $bindParams All variables to bind to the SQL statment.
191+ * @param bool $sanitize If query should be filtered before execution
191192 *
192193 * @return array Contains the returned rows from the query.
193194 */
194- public function rawQuery ($ query , $ bindParams = null )
195+ public function rawQuery ($ query , $ bindParams = null , $ sanitize = true )
195196 {
196- $ this ->_query = filter_var ($ query , FILTER_SANITIZE_STRING ,
197+ $ this ->_query = $ query ;
198+ if ($ sanitize )
199+ $ this ->_query = filter_var ($ query , FILTER_SANITIZE_STRING ,
197200 FILTER_FLAG_NO_ENCODE_QUOTES );
198201 $ stmt = $ this ->_prepareQuery ();
199202
Original file line number Diff line number Diff line change @@ -127,8 +127,14 @@ if($db->delete('users')) echo 'successfully deleted';
127127```
128128
129129### Generic Query Method
130+ By default rawQuery() will filter out special characters so if you getting problems with it
131+ you might try to disable filtering function. In this case make sure that all external variables are passed to the query via bind variables
132+
130133``` php
131- $users = $db->rawQuery('SELECT * from users');
134+ // filtering enabled
135+ $users = $db->rawQuery('SELECT * from users where customerId=?', Array (10));
136+ // filtering disabled
137+ //$users = $db->rawQuery('SELECT * from users where id >= ?', Array (10), false);
132138foreach ($users as $user) {
133139 print_r ($user);
134140}
You can’t perform that action at this time.
0 commit comments