Home > Backend Development > PHP7 > body text

php5 upgrade php7 fails to connect to mysql database

王林
Release: 2023-02-17 12:52:01
Original
4071 people have browsed it

php5 upgrade php7 fails to connect to mysql database

Reason:

php5 uses the mysql_connect function to connect to the Mysql database, but you will find that this method does not work on php7 It works. The reason is very simple. php7 has abandoned this function. Now php7 probably uses two methods to connect to the MySQL database.

Method 1:

Use function connection. The original mysql_connect() is changed to the mysqli_connect() function. If you add this letter, everything will be normal.

Syntax:

变量名 = mysqli_connect(主机地址,用户名,密码,数据库名);
Copy after login

Method 2:

Use object-oriented method.

Grammar:

变量名 = new mysqli(主机地址,用户名,密码,数据库名);
Copy after login

Recommended tutorial: PHP7 tutorial

The above is the detailed content of php5 upgrade php7 fails to connect to mysql database. 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