Home  >  Article  >  Backend Development  >  How to print database error information in php

How to print database error information in php

藏色散人
藏色散人Original
2021-09-26 09:12:362478browse

How to print database error information in php: 1. Create a PHP sample file; 2. Connect to the database through mysql_connect; 3. Print the database error information through the mysql_error function.

How to print database error information in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

How to print database error information in php?

The code is as follows:

$link = @mysql_connect("服务器", "账号", "密码") or die("自己的错误解释".mysql_error());   
echo mysql_error(); //打印数据错误信息

Related introduction:

mysql_error

(PHP 4, PHP 5 )

mysql_error — Returns the text error message generated by the previous MySQL operation

Description

mysql_error(resource $link_identifier = ?): string

Returns the error text of the previous MySQL function, if there is no error, returns ''( empty string). If no connection resource number is specified, the last successfully opened connection is used to extract error information from the MySQL server.

Errors from the MySQL database backend no longer issue warnings, use mysql_error() to extract the error text. Note that this function only returns the error text from the most recent execution of a MySQL function (excluding mysql_error() and mysql_errno()), so if you want to use this function, be sure to check its value before calling another MySQL function.

mysqli_error()

mysqli_error() function returns the last error description of the most recently called function.

Syntax

mysqli_error(connection);

Parameters

connection required. Specifies the MySQL connection to use.

Return value: Returns a string with an error description. Returns "" if no error occurred.

PHP Version: 5

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to print database error information 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