PHP Error: Undefined Function "mysql_connect()"
Having set up PHP, MySQL, and Apache, a common PHP error message that users encounter is "Fatal error: Call to undefined function mysql_connect()". This error typically occurs when you attempt to use the "mysql_connect()" function, which is a deprecated function in PHP 7 and later versions.
To resolve this issue, determine your PHP version by running the following command:
php -version
If the result indicates PHP 7 or above, you need to migrate from "mysql_" functions to their updated counterparts, "mysqli_" functions. Here's an example of how to update your code:
$host = "127.0.0.1"; $username = "root"; $pass = "foobar"; $con = mysqli_connect($host, $username, $pass, "your_database");
This change will allow you to use the "mysqli_connect()" function and establish a connection to your MySQL database. Remember to update all your "mysql_" functions with their "mysqli_" counterparts when upgrading from legacy PHP versions.
The above is the detailed content of Why Does PHP Throw a \'Fatal error: Call to undefined function mysql_connect()\' Error, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!