<?php function escape(string $query) { return preg_replace_callback('/{(([^.}]+?)\.)?(.*?)}/', function ($matches) { $quoted = ''; // Quote table name. If there is an explicit database, quote it, too. if ($matches[2] !== '') { $quoted .= '`' . $matches[2] . '`.'; } // Quote the table name, keeping curly brackets so potential prefixes can // be added later. $quoted .= '`{' . $matches[3] . '}`'; return $quoted; }, $query); } var_dump(escape('SELECT * FROM system')); var_dump(escape('SELECT * FROM {system} ')); var_dump(escape('SELECT * FROM {db.system}')); var_dump(escape('SELECT * FROM db.system'));
You have javascript disabled. You will not be able to edit any code.