I have set up PHP, MySQL, and Apache. localhost()
for PHP and it is working well. But after I downloaded MySQL, it reports:
Fatal error: Call to undefined function mysql_connect()
How can I fix this?
This error is encountered when we try to use “mysql_connect()” functions of php5 in php7. PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() error is raised because mysql_* functions are completely removed from PHP 7, it previously got deprecated in PHP 5.5, but now it is completely removed.
mysql_connect() establishes a connection to a MySQL server. The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password. The server parameter can also include a port number.
You upgraded to PHP 7, and now mysql_connect
is deprecated. Check yours with:
php -version
Change it to mysqli_connect
as in:
$host = "127.0.0.1"; $username = "root"; $pass = "foobar"; $con = mysqli_connect($host, $username, $pass, "your_database");
If you're upgrading legacy PHP, now you're faced with the task of upgrading all your mysql_*
functions with mysqli_*
functions.
If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.
mysql_connect — Open a connection to a MySQL Server
Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
More here: http://php.net/manual/en/function.mysql-connect.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With