Home > Article > Backend Development > What to do if php7 fails to connect to mysql
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.
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!