Blindly rewriting the input seems dangerous enough as it is. Your proposal means any sequence of digits followed by an underscore will be replaced, whereas it can currently only happen to the string "0_".
I suggest line 305 be removed. Or at the very least be changed to consider some context. To make it foolproof we would need a parser for SQL, but extending the matched strings to each of the "allowed commands" might be good enough. At least until someone starts storing SQL queries in the database...
I'm thinking something like
preg_replace("/CREATE TABLE \d+_/i", "CREATE TABLE ".$connection['tbpref'], $line);
preg_replace("/INSERT INTO \d+_/i", "INSERT INTO ".$connection['tbpref'], $line);
...
It might work, but it's not pretty.