Home >Backend Development >PHP Tutorial >How to Fix \'Fatal Error: Call to Undefined Function mysql_connect()\'?
PHP Error: Unable to Connect to MySQL Database
You have encountered a "Fatal error: Call to undefined function mysql_connect()." This error indicates that PHP is unable to access the MySQL function mysql_connect().
Upon further investigation, you find that you have recently upgraded to PHP 7, which has deprecated the mysql_connect() function in favor of mysqli_connect().
Solution:
To resolve this error, you need to update your PHP code to use the mysqli_connect() function instead of mysql_connect(). Here's an example of how to do this:
<code class="php">$host = "127.0.0.1"; $username = "root"; $pass = "foobar"; $con = mysqli_connect($host, $username, $pass, "your_database");</code>
Additionally, if you are upgrading legacy PHP code, you will need to replace all instances of mysql_* functions with their corresponding mysqli_* counterparts.
The above is the detailed content of How to Fix \'Fatal Error: Call to Undefined Function mysql_connect()\'?. For more information, please follow other related articles on the PHP Chinese website!