Skip to content

Commit 32b81aa

Browse files
committed
Allow backticks in order by
1 parent 6407b01 commit 32b81aa

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

MysqliDb.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,14 @@ public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields
469469
{
470470
$allowedDirection = Array ("ASC", "DESC");
471471
$orderbyDirection = strtoupper (trim ($orderbyDirection));
472-
$orderByField = preg_replace ("/[^-a-z0-9\.\(\),_]+/i",'', $orderByField);
472+
$orderByField = preg_replace ("/[^-a-z0-9\.\(\),_`]+/i",'', $orderByField);
473473

474474
if (empty($orderbyDirection) || !in_array ($orderbyDirection, $allowedDirection))
475475
die ('Wrong order direction: '.$orderbyDirection);
476476

477477
if (is_array ($customFields)) {
478478
foreach ($customFields as $key => $value)
479-
$customFields[$key] = preg_replace ("/[^-a-z0-9\.\(\),_]+/i",'', $value);
479+
$customFields[$key] = preg_replace ("/[^-a-z0-9\.\(\),_`]+/i",'', $value);
480480

481481
$orderByField = 'FIELD (' . $orderByField . ', "' . implode('","', $customFields) . '")';
482482
}

tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ function createTable ($name, $data) {
157157
$db->rawQuery($q);
158158

159159

160-
$db->orderBy("id","asc");
160+
$db->orderBy("`id`","asc");
161161
$users = $db->get("users");
162162
if ($db->count != 3) {
163163
echo "Invalid total insert count";
164164
exit;
165165
}
166+
echo $db->getLastQuery();
166167

167168
// order by field
168169
$db->orderBy("login","asc", Array ("user3","user2","user1"));

0 commit comments

Comments
 (0)