Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined function mysql_connect()

Tags:

php

mysql

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?

like image 648
pepsicode Avatar asked May 16 '12 09:05

pepsicode


People also ask

What is Call to undefined function mysql_connect ()?

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.

What does the mysql_connect () function do?

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.


2 Answers

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.

like image 133
user3325593 Avatar answered Sep 24 '22 01:09

user3325593


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

like image 31
argoden Avatar answered Sep 23 '22 01:09

argoden