php – Fatal error: Call to undefined function mysql_connect()

php – Fatal error: Call to undefined function mysql_connect()

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 youre upgrading legacy PHP, now youre 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

php – Fatal error: Call to undefined function mysql_connect()

Open your terminal and run bellow command.

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql 5:

sudo apt-get install php5-mysql

Leave a Reply

Your email address will not be published.