mysql_errno
Returns the numeric encoding of the error message in the previous MySQL operation.
Function name: mysql_errno()
Applicable version: PHP 4, PHP 5, PHP 7
Usage: The mysql_errno() function is used to get the error code of the last MySQL operation.
Syntax: int mysql_errno ( [resource $link_identifier = NULL] )
parameter:
Return value: Returns an integer value representing the error code of the most recent MySQL operation, and if no error occurs, return 0.
Example:
$conn = mysql_connect("localhost", "username", "password"); mysql_select_db("database", $conn); $query = "SELECT * FROM table"; $result = mysql_query($query); if(mysql_errno() != 0){ echo "MySQL 错误码:" . mysql_errno() . "<br>"; echo "MySQL 错误信息:" . mysql_error() . "<br>"; } else { // 执行成功的操作}
$conn1 = mysql_connect("localhost", "username1", "password1"); $conn2 = mysql_connect("localhost", "username2", "password2"); mysql_select_db("database1", $conn1); mysql_select_db("database2", $conn2); $query1 = "SELECT * FROM table1"; $query2 = "SELECT * FROM table2"; $result1 = mysql_query($query1, $conn1); $result2 = mysql_query($query2, $conn2); if(mysql_errno($conn1) != 0){ echo "MySQL 错误码:" . mysql_errno($conn1) . "<br>"; echo "MySQL 错误信息:" . mysql_error($conn1) . "<br>"; } else { // 执行成功的操作} if(mysql_errno($conn2) != 0){ echo "MySQL 错误码:" . mysql_errno($conn2) . "<br>"; echo "MySQL 错误信息:" . mysql_error($conn2) . "<br>"; } else { // 执行成功的操作}
Notes: