Home >Backend Development >PHP Problem >What to do if php7 fails to connect to mysql

What to do if php7 fails to connect to mysql

藏色散人
藏色散人Original
2021-11-01 10:59:532641browse

php7 fails to connect to mysql because php7 has abandoned the mysql_connect function. The solution is: 1. Use the mysqli_connect() function to connect; 2. Use the object-oriented method to connect to mysql.

What to do if php7 fails to connect to mysql

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

What should I do if php7 fails to connect to mysql?

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. 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: variable name = mysqli_connect (host address, user name, password, database name);

Method 2:

Use object-oriented method.

Grammar:

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

Recommended learning: "PHP Video Tutorial"

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