Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined function mysql_connect()

I have ran aptitude install php5-mysql (and restarted MySQL/Apache 2), but I am still getting this error:

Fatal error: Call to undefined function mysql_connect() in /home/validate.php on line 21

phpinfo() says the /etc/php5/apache2/conf.d/pdo_mysql.ini file has been parsed.

like image 533
user1765369 Avatar asked Dec 11 '12 17:12

user1765369


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.

What is fatal error call to undefined function?

Call to undefined function error clearly shows that its not getting your function where you have defined. Reason is you are attaching full path of settings. php file with http . You need to include settings. php file without http path at the top of 'index.

Is mysql_connect deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.


1 Answers

In case, you are using PHP7 already, the formerly deprecated functions mysql_* were removed entirely, so you should update your code using the PDO-functions or mysqli_* functions instead.

If that's not possible, as a workaround, I created a small PHP include file, that recreates the old mysql_* functions with mysqli_*()-functions: fix_mysql.inc.php

like image 74
rubo77 Avatar answered Sep 28 '22 00:09

rubo77