mysqli_query错误和while循环

时间:2017-01-14 16:27:38

标签: php

我是php的新手,下面真的需要帮助。

echo "Running Database Script...";
flush();
$dbms_schema = "../../sql/schema.sql";

$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('Cannot find SQL schema file. ');

$sql_query = remove_remarks($sql_query);
$sql_query = remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';');

$con = mysqli_connect($servername,'root',$rootpass) or die('error connection');

$i=1;
foreach($sql_query as $sql){
  //echo $i++;
  //echo "  ";
  //echo $sql;
  //echo "<br>";
  mysqli_query($con,$sql) or die('error in query');
}
//mysqli_close($con);
echo "Success!<br>";
flush();

使用mysqli_query($ con,$ sql)部分得到以下结果...

Running Database Script...error in query

1 个答案:

答案 0 :(得分:0)

尝试使用mysqli_error()显示错误:

if (!mysqli_query($con,$sql)) {
    printf("Errormessage: %s\n", mysqli_error($con));
}