What should I do if php cannot connect to the database?

藏色散人
Release: 2023-03-08 20:04:01
Original
5245 people have browsed it

php cannot connect to the database because PHP7 has abandoned the connect method and cannot connect to the database. The solution is to use the mysqli method to connect to the database.

What should I do if php cannot connect to the database?

The operating environment of this article: Ubuntu16 system, PHP7.0 version, DELL G3 computer

PHP cannot connect to the database?

I used the connect method to connect to the database successfully, but now it fails. The code is as follows:

<?php
$con = mysql_connect("localhost","root","code");
if (!$con)
{
die(&#39;Could not connect: &#39; . mysql_error());
}
mysql_close($con);
?>
Copy after login

My Ubuntu is version 16 and PHP is 7.0. Finally, I found that PHP7 has abandoned the connect method and used PDO and mysqli instead. I switched to the mysqli method and it was successful. For specific operations, please see the tutorial below:

PDO:

//m.sbmmt.com/php/php-pdo .html

Mysqli:

//m.sbmmt.com/php/php-ref-mysqli.html

The above is the detailed content of What should I do if php cannot connect to the database?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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