Current Location: Home> Function Categories> mysql_error

mysql_error

Returns the text error message generated by the previous MySQL operation.
Name:mysql_error
Category:Uncategorized
Programming Language:php
One-line Description:Returns the error message generated by the last MySQL operation

Function name: mysql_error()

Applicable version: PHP 4, PHP 5, PHP 7

Usage: The mysql_error() function is used to return the error message generated by the last MySQL operation.

Syntax: string mysql_error ([ resource $link_identifier = NULL ] )

parameter:

  • link_identifier (optional): A MySQL connection identifier. If this parameter is not provided, the function uses the recently opened connection. If no connection is found, a new connection is attempted. If the connection fails, FALSE is returned.

Return value: Returns the error message generated by the most recent MySQL operation, and if no error occurs, an empty string is returned.

Example:

 <?php $link = mysql_connect('localhost', 'user', 'password'); if (!$link) { die('连接数据库失败:' . mysql_error()); } $db_selected = mysql_select_db('mydb', $link); if (!$db_selected) { die ('选择数据库失败:' . mysql_error($link)); } // 执行查询操作$result = mysql_query('SELECT * FROM mytable', $link); if (!$result) { die('查询失败:' . mysql_error($link)); } // 关闭连接mysql_close($link); ?>

Notes:

  1. The mysql_error() function can only return error information generated by the last MySQL operation. If an error occurred in the previous operation, the function will not be retrieved.
  2. Starting with PHP version 5.5.0, the mysql_* series of functions have been deprecated, and it is recommended to use MySQLi or PDO extensions to operate the MySQL database.
Similar Functions
Popular Articles