Home > Article > Backend Development > What should I do if an error occurs when php connects to mysql database?
The solution to the error when php connects to the mysql database is: 1. Open the environment variable settings and add the php installation directory after the Path variable; 2. Restart the computer; 3. Copy the libmysql.dll file to the apache server In the bin directory; 4. Restart the apache server.
Error description:
(Recommended tutorial: php tutorial)
PHP connection mysql database When, the following error occurs: Fatal error: Call to undefined function mysql_connect() in.......
Analysis:
This error usually occurs when PHP, Mysql, and Apache servers are configured.
The solution is as follows:
It can be solved by modifying the environment variables.
The specific operation is:
1. Right-click "My Computer", click "Properties", "Advanced", "Environment Variables";
2. Edit the "Path" variable under "System Variables" and add ";E:\php\php5;E:\php\php5\ext" after the original value. ("E:\php\php5" is the installation directory of php)
3. Restart the computer;
4. Copy libmysql.dll in the php installation directory to the bin directory of the apache server Below;
5. Restart the apache server.
Test: test.php
Where user is the username of MySQL, userpassword is the corresponding user password of MySQL
<?php $link=mysql_connect('localhost','[user]','[userpassword]'); if(!$link) echo "fail"; else echo "success"; mysql_close(); ?>
Save the test code in the htdocs of the apache installation directory Next, after starting the server, enter "http://localhost/test.php" in the browser. If "success" appears, it means that PHP has successfully connected to the database.
The above is the detailed content of What should I do if an error occurs when php connects to mysql database?. For more information, please follow other related articles on the PHP Chinese website!