I want to add a prefix to tables and have recently written a PHP script to extract all tables in a string SQL query.
$sql = 'UPDATE festivals SET desc = "Starts from July"';
preg_match_all('/(from|into|update|table|join) (`?\w+`?)\s/i', $sql, $matches);
It works good but the only problem is that it extracts July
because it does not distinguish between a SQL value and a real table name, so it assumes that July
would be a table too.
Now I think the solution should be something to prevent extract what wrapped in a single or double quotation but don't know how to do that.