function executeSQL($myFile)
{
$sql = file_get_contents($myFile);//echo $sql;
$sqllines = split("\n",$sql);
//print_r($sqllines);
$cmd = '';
$delim = false;
foreach($sqllines as $l)
{
if(preg_match('/^\s*--/',$l) == 0)//去除所有非--开头的
{
if(preg_match('/DELIMITER \$\$/',$l) != 0)
{
$delim = true;//是
}
else
{
if(preg_match('/DELIMITER ;/',$l) != 0)
{
$delim = false;
}
else
{
if(preg_match('/END\$\$/',$l) != 0)
{
$cmd .= ' END';
}
else
{
$cmd .= ' ' . $l . "\n";
}
}
if(preg_match('/.+;/',$l) != 0 && !$delim)//完整SQL语句
{echo '<br><br>'.$cmd.'<br><br>';
$result = mysql_query($cmd) or die(mysql_error());
$cmd = '';
}
}
}
}
}然后调用$myFile = "angelsis-4.9-schema-mysql.sql";
echo '开始执行我啦!!!!!!!';
var_dump(executeSQL($myFile));
$myFile = "angelsis-4.9-procs-mysql.sql";
executeSQL($myFile);
echo '貌似执行不到我啦!!!!!!!1';第一次调用executeSQL,SQL大概1700多行,执行到1300多行时就停止了,不知道为什么,第二次就直接不再执行了,程序就挂在那里了……http://sdaujdxy.co.cc/install.rar
{
$sql = file_get_contents($myFile);//echo $sql;
$sqllines = split("\n",$sql);
//print_r($sqllines);
$cmd = '';
$delim = false;
foreach($sqllines as $l)
{
if(preg_match('/^\s*--/',$l) == 0)//去除所有非--开头的
{
if(preg_match('/DELIMITER \$\$/',$l) != 0)
{
$delim = true;//是
}
else
{
if(preg_match('/DELIMITER ;/',$l) != 0)
{
$delim = false;
}
else
{
if(preg_match('/END\$\$/',$l) != 0)
{
$cmd .= ' END';
}
else
{
$cmd .= ' ' . $l . "\n";
}
}
if(preg_match('/.+;/',$l) != 0 && !$delim)//完整SQL语句
{echo '<br><br>'.$cmd.'<br><br>';
$result = mysql_query($cmd) or die(mysql_error());
$cmd = '';
}
}
}
}
}然后调用$myFile = "angelsis-4.9-schema-mysql.sql";
echo '开始执行我啦!!!!!!!';
var_dump(executeSQL($myFile));
$myFile = "angelsis-4.9-procs-mysql.sql";
executeSQL($myFile);
echo '貌似执行不到我啦!!!!!!!1';第一次调用executeSQL,SQL大概1700多行,执行到1300多行时就停止了,不知道为什么,第二次就直接不再执行了,程序就挂在那里了……http://sdaujdxy.co.cc/install.rar
display_errors=On
error_reporting=E_ALL & ~NOTICE