Home  >  Article  >  Backend Development  >  What should I do if an error occurs when php connects to mysql database?

What should I do if an error occurs when php connects to mysql database?

王林
王林Original
2020-07-10 11:03:473651browse

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.

What should I do if an error occurs when php connects to mysql database?

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(&#39;localhost&#39;,&#39;[user]&#39;,&#39;[userpassword]&#39;);
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!

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