I've wrote this function for my site admin tool (Drake Admin), isn't perfect because ignore the comments but if you insert another query after ; not in a new line, the query is ignored, but can help.
function execute_sql_script($filename)
{
$fd = fopen($filename, "r");
$query = "";
while(!feof ( $fd ))
{
$line = fgets($fd, 4096);
if ( $line{1} == '#' )
continue;
if ( strstr($line, "#") != false )
$line = substr($line, 0, strpos($line, "#"));
if ( strstr($line, ";") != false )
{
$query .= substr($line, 0, strpos($line, ";"));
mysql_query($query);
if ( mysql_errno() )
echo "<font color=\"red\">Error executing query</font><br><pre>$query</pre><br>".mysql_errno().": ".mysql_error()."<br>\n";
$query = "";
} else
$query .= $line;
}
}