diff --git a/admin/configuration.php b/admin/configuration.php index 95ba049d4..2274ab75a 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -122,7 +122,7 @@ $sort_fields = array( 'hit ASC' => l10n('Visits, low → high'), 'id ASC' => l10n('Numeric identifier, 1 → 9'), 'id DESC' => l10n('Numeric identifier, 9 → 1'), - 'rank ASC' => l10n('Manual sort order'), + '`rank` ASC' => l10n('Manual sort order'), ); $comments_order = array( diff --git a/admin/element_set_ranks.php b/admin/element_set_ranks.php index 07b20c95b..7defa3c3b 100644 --- a/admin/element_set_ranks.php +++ b/admin/element_set_ranks.php @@ -71,7 +71,7 @@ if (isset($_POST['submit'])) } elseif ($image_order_choice=='rank') { - $image_order = 'rank ASC'; + $image_order = '`rank` ASC'; } $query = ' UPDATE '.CATEGORIES_TABLE.' diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index 37924fecd..03eed5f53 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -49,7 +49,7 @@ $query.= ' if ('recent_cats' != $page['section']) { $query.= ' - ORDER BY rank'; + ORDER BY `rank`'; } $result = pwg_query($query); diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php index 25e589162..1ea188f42 100644 --- a/include/dblayer/functions_mysql.inc.php +++ b/include/dblayer/functions_mysql.inc.php @@ -61,7 +61,7 @@ function pwg_get_db_version() return mysql_get_server_info(); } -function pwg_query($query, $escape_reserved_words=true) +function pwg_query($query) { global $conf,$page,$debug,$t2; diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index f9a68d391..63d2babbf 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -124,27 +124,10 @@ function pwg_get_db_version() * @param string $query * @return mysqli_result|bool */ -function pwg_query($query, $escape_reserved_words=true) +function pwg_query($query) { global $mysqli, $conf, $page, $debug, $t2; - // starting with MySQL 8, rank becomes a reserved keyword, we need to escape it - if ($escape_reserved_words and preg_match('/\brank\b/', $query)) - { - // first we unescape what's already escaped (to avoid double escaping) - $query = preg_replace('/`rank`/', 'rank', $query); - // then we escape the keyword - $query = preg_replace('/\brank\b/', '`rank`', $query); - } - - if ($escape_reserved_words and preg_match('/\bgroups\b/', $query)) - { - // first we unescape what's already escaped (to avoid double escaping) - $query = preg_replace('/`groups`/', 'groups', $query); - // then we escape the keyword - $query = preg_replace('/\bgroups\b/', '`groups`', $query); - } - $start = microtime(true); ($result = $mysqli->query($query)) or my_error($query, $conf['die_on_sql_error']); diff --git a/include/functions.inc.php b/include/functions.inc.php index 2225197ff..6c324b145 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1381,7 +1381,7 @@ INSERT INTO ON DUPLICATE KEY UPDATE value = \''.$dbValue.'\' ;'; - pwg_query($query, false); + pwg_query($query); if ($updateGlobal) { diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index 89c9b3224..b7643bdfe 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -581,7 +581,7 @@ function ws_categories_setRank($params, &$service) { // does the category really exist? $query = ' -SELECT id, id_uppercat, rank +SELECT id, id_uppercat, `rank` FROM '.CATEGORIES_TABLE.' WHERE id IN ('.implode(',',$params['category_id']).') ;'; diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 5ff3bb5cd..ecb3ccd57 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -112,9 +112,9 @@ DELETE if ($search_current_ranks) { $query = ' -SELECT category_id, MAX(rank) AS max_rank +SELECT category_id, MAX(`rank`) AS max_rank FROM '.IMAGE_CATEGORY_TABLE.' - WHERE rank IS NOT NULL + WHERE `rank` IS NOT NULL AND category_id IN ('.implode(',', $new_cat_ids).') GROUP BY category_id ;'; @@ -744,7 +744,7 @@ SELECT image_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$params['category_id'].' - ORDER BY rank ASC + ORDER BY `rank` ASC ;'; $image_ids = query2array($query, null, 'image_id'); @@ -790,7 +790,7 @@ SELECT COUNT(*) // what is the current higher rank for this category? $query = ' -SELECT MAX(rank) AS max_rank +SELECT MAX(`rank`) AS max_rank FROM '. IMAGE_CATEGORY_TABLE .' WHERE category_id = '. $params['category_id'] .' ;'; @@ -811,17 +811,17 @@ SELECT MAX(rank) AS max_rank // update rank for all other photos in the same category $query = ' UPDATE '. IMAGE_CATEGORY_TABLE .' - SET rank = rank + 1 + SET `rank` = `rank` + 1 WHERE category_id = '. $params['category_id'] .' - AND rank IS NOT NULL - AND rank >= '. $params['rank'] .' + AND `rank` IS NOT NULL + AND `rank` >= '. $params['rank'] .' ;'; pwg_query($query); // set the new rank for the photo $query = ' UPDATE '. IMAGE_CATEGORY_TABLE .' - SET rank = '. $params['rank'] .' + SET `rank` = '. $params['rank'] .' WHERE image_id = '. $params['image_id'] .' AND category_id = '. $params['category_id'] .' ;';