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!