如何查看MySQL查询错误详细信息


How to see MySQL query error details?

我试图插入到一个表,但它不工作。我告诉我的应用,如果不能插入,就重定向到home。php,它就是这样做的。所以,这里肯定有错误。但是,它没有告诉我,有办法看到查询错误吗?下面是代码:

if(0 === count($errors)){
// Sanitize name and phone number
  $contact_name = mysql_real_escape_string($_POST['name']);
  $phone_number  = mysql_real_escape_string($_POST['phone_number']);
  $query = "INSERT INTO `ani` (`ContactName`,  `PhoneNumber`)
            VALUES            ('$contact_name', '$phone_number'";
  $result = mysql_query($query);
  if(mysql_errno() === 0){
    header("Location: pinless.php");
  } else {
    header("Location: home.php");
    // Here I want to see what the heck is wrong with the above query
    // instead of redirecting
  }
}
echo mysql_error();

echo mysql_errno();  
echo mysql_error();

php.net手册