Skip to content

Commit 89c80f1

Browse files
committed
Added param to rawQuery() to disable query variable filtering
1 parent 5cf4753 commit 89c80f1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

MysqliDb.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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);
132138
foreach ($users as $user) {
133139
print_r ($user);
134140
}

0 commit comments

Comments
 (0)