Home  >  Article  >  Backend Development  >  How to get mysql error message in php

How to get mysql error message in php

王林
王林Original
2020-08-18 16:50:242936browse

php method to obtain mysql error information: You can use the mysql_error() function to obtain it. The mysql_error() function can return the text error message generated by the previous mysql operation, or an empty string if there is no error.

How to get mysql error message in php

The mysql_error() function returns the text error message generated by the previous MySQL operation, or an empty string if there is no error.

(Recommended tutorial: php graphic tutorial)

Grammar:

mysql_error(connection)

(Recommended learning video: php video tutorial )

Example:

<?php
$con = mysql_connect("localhost","wrong_user","wrong_pwd");
if (!$con)
  {
  die(mysql_error());
  }
mysql_close($con);
?>

Output result:

Access denied for user &#39;wrong_user&#39;@&#39;localhost&#39;
(using password: YES)

The above is the detailed content of How to get mysql error message in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn