如何在php中显示查询错误

时间:2017-04-10 04:49:48

标签: php mysql mysqli

我有一个不会执行的mysqli查询,我想显示有关为什么会发生这种情况的信息。我只是在这个例子中鬼混,但我想这样的事情:

$myQuery= $mysqli->query("UPDATE table SET id = 1 WHERE id = 3");
if(!$myQuery) //If query couldnt be executed
{
echo $mysqli->error; //Display information about why wasnt executed (eg. Error: couldnt find table)
}

1 个答案:

答案 0 :(得分:3)

尝试使用

// Perform a query, check for error
if (!mysqli_query($con,"UPDATE table SET id = 1 WHERE id = 3"))
{
 echo("Error description: " . mysqli_error($con));
}

mysqli_close($con);