Home  >  Article  >  Backend Development  >  php5 upgrade php7 fails to connect to mysql database

php5 upgrade php7 fails to connect to mysql database

王林
王林Original
2019-10-18 15:32:494046browse

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(主机地址,用户名,密码,数据库名);

Method 2:

Use object-oriented method.

Grammar:

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

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!

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