Hướng dẫn php mysql error handling

mysqli_connect_error

[PHP 5, PHP 7, PHP 8]

Nội dung chính

  • mysqli_connect_error
  • Description
  • Return Values
  • Description
  • Return Values
  • How do I fix PHP connection error?
  • What is CONN
  • How show MySQL error message in PHP?
  • How can I get PDO exception in PHP?

mysqli::$connect_error -- mysqli_connect_errorReturns a description of the last connection error

Description

Object-oriented style

Procedural style

mysqli_connect_error[]: ?string

Parameters

This function has no parameters.

Return Values

A string that describes the error. null is returned if no error occurred.

Examples

Example #1 $mysqli->connect_error example

Object-oriented style

The above example will output something similar to:

1049: Unknown database 'nonexistentdb'
1146: Table 'kossu.nonexistenttable' doesn't exist

See Also

  • mysql_errno[] - Returns the numerical value of the error message from previous MySQL operation
  • » MySQL error codes

aleczapka _at] gmx dot net

18 years ago

If you want to display errors like "Access denied...", when mysql_error[] returns "" and mysql_errno[] returns 0, use  $php_errormsg. This Warning will be stored there.  You need to have track_errors set to true in your php.ini.

Note. There is a bug in either documentation about error_reporting[] or in mysql_error[] function cause manual for mysql_error[], says:  "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.

Florian Sidler

12 years ago

Be aware that if you are using multiple MySQL connections you MUST support the link identifier to the mysql_error[] function. Otherwise your error message will be blank.

Just spent a good 30 minutes trying to figure out why i didn't see my SQL errors.

Pendragon Castle

13 years ago

Using a manipulation of josh >'s function, I created the following. It's purpose is to use the DB to store errors. It handles both original query, as well as the error log. Included Larry Ullman's escape_data[] as well since I use it in q[].

Chủ Đề