<?php
$sql_file = 'test.sql';
$contents = file_get_contents($sql_file);
// Remove C style and inline comments
$comment_patterns = array('/\/\*.*(\n)*.*(\*\/)?/', //C comments
'/\s*--.*\n/', //inline comments start with --
'/\s*#.*\n/', //inline comments start with #
);
$contents = preg_replace($comment_patterns, "\n", $contents);
//Retrieve sql statements
$statements = explode(";\n", $contents);
$statements = preg_replace("/\s/", ' ', $statements);
mysql_connect('','','');
foreach ($statements as $query) {
if (trim($query) != '') {
echo 'Executing query: ' . $query . "\n";
$res = mysql_query($query);
if (mysql_error()) {
die(mysql_error());
}
}
}
?>