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.
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 ormysqli_*
functions instead.If that's not possible, as a workaround, I created a small PHP include file, that recreates the old
mysql_*
functions withmysqli_*()
-functions: fix_mysql.inc.phpThe question is tagged with
ubuntu
, but the solution of un-commenting theextension=mysqli.dll
is specific to windows. I am confused here?!, anyways, first thing run<? php phpinfo ?>
and search formysql*
underConfiguration
heading. If you don't see such a thing implies you have not installed or enabledphp-mysql
. So first installphp-mysql
sudo apt get install php-mysql
This command will install
php-mysql
depending on thephp
you have already installed, so no worries about the version!!.Then comes the unix specific solution, in the
php.ini
file un-comment the lineverify that
msql.so
is present in/usr/lib/php/<timestamp_folder>
, ELSEThen finally restart the
apache
andmysql
services, and you should now see themysql
section underConfigrations
heading inphpinfo page
There must be some syntax error. Copy/paste this code and see if it works:
I had the same error message. It turns out I was using the
msql_connect()
function instead ofmysql_connect()
.In php.ini file
change this
into
Try:
Run the page and search for
mysql
. If not found, run the following in the shell and restart the Apache server:Also make sure you have all the following lines uncommented somewhere in your apache2.conf (or in your conf.d/php.ini) file, from
to
I was also stuck with the same problem of undefined MySQL_connect().I tried to make changes in PHP.ini file but it was giving me the same error. Then I came to this solution where I changed my code from depreciated php functions to new functions.
I hope this will help you . This solution is correctly working for me .