Home >Backend Development >PHP Tutorial >How to Resolve \'Fatal error: Call to undefined function mysql_connect()\' in PHP?
Understanding the "Fatal error: Call to undefined function mysql_connect()" Issue
When encountering this error message in your PHP script, it indicates that the mysql_connect() function is missing or not recognized by your system. This error often occurs after upgrading to PHP version 7.0 or higher.
Cause of the Error
In PHP 7.0, the mysql_* functions, including mysql_connect(), were deprecated due to concerns about security and performance. As a result, these functions are no longer available and should be replaced with their mysqli or PDO counterparts.
Solution: Upgrade to mysqli_connect
To resolve this error, you will need to upgrade your code to use the mysqli extension. Here's how:
Example:
<code class="php">$host = "127.0.0.1"; $username = "root"; $pass = "foobar"; $con = mysqli_connect($host, $username, $pass, "your_database");</code>
Remember that upgrading to PHP 7.0 or higher requires a careful review of your existing code to ensure compatibility. By replacing deprecated functions with their modern counterparts, you can eliminate potential errors and maintain the security and performance of your PHP applications.
The above is the detailed content of How to Resolve \'Fatal error: Call to undefined function mysql_connect()\' in PHP?. For more information, please follow other related articles on the PHP Chinese website!