diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index 6f8c6d683..ed2e8d738 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -128,6 +128,15 @@ 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 (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); + } + $start = microtime(true); ($result = $mysqli->query($query)) or my_error($query, $conf['die_on_sql_error']);