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

What to do if php mysql connection fails

藏色散人
Release: 2023-03-03 09:44:02
Original
4384 people have browsed it

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.

<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
  {
  die(&#39;连接失败&#39; . mysql_error());
  }
?>
Copy after login

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
Copy after login

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()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template