Home>Article>Backend Development> What to do if php mysql connection fails

What to do if php mysql connection fails

藏色散人
藏色散人 Original
2020-07-25 09:18:03 4272browse

php mysql connection fails because higher versions of php no longer use "mysql_connect()" to connect to the MySQL database. The solution is to use mysqli or PDO to replace "mysql_connect" and reconnect to mysql.

What to do if php mysql connection fails

Recommended: "PHP Tutorial"

PHP cannot connect to MySQL and failed

Higher versions of php no longer use mysql_connect() to connect to the MySQL database.

Today I used the above code to link to my database, but it failed. Tip me:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in D:\Sian\Blog pages\demo.php on line 2

mysql_connect() has been deprecated and will be deleted in the future. Use mysqli or PDO to replace it.

Then the PHP official website explains it this way:

mysql_connect - Open a connection to the MySQL server

Warning

This extension is available since PHP 5.5.0 Deprecated and removed starting with PHP 7.0.0. It should be replaced with the MySQLi or PDO_MySQL extension. See the MySQL: Selection API guide and related FAQ for more information.

The alternatives to this function are:

mysqli_connect() PDO::__construct()

The above is the detailed content of What to do if php mysql connection fails. 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