在我的代码中,我执行了几个有效的SQL语句。但是其中一个语句无效($ mysqli-> prepare返回false),但没有返回错误代码($ mysqli-> error返回false)。
下面的代码示例:
$mysqli = new mysqli('host', 'user', 'password', 'database');
// First query (valid)
if(($oStatement = $mysqli->prepare('SELECT column FROM table;')) === false)
throw new Exception('Error in statement: ' . $mysqli->error);
// ...
// Second query (invalid)
if(($oStatement = $mysqli->prepare('SELECT column_which_doesnt_exist FROM table;')) === false)
throw new Exception('Error in statement: ' . $mysqli->error);
为什么它不返回错误信息?
有趣的发现,谢谢你的分享。 JFYI http://stackoverflow.com/questions/18457821/how-to-make-mysqli-throw-exceptions-using-mysqli-report-strict –