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.
Well, this is your chance! It looks like PDO is ready; use that instead.
Try checking to see if the PHP MySQL extension module is being loaded:
If it's not there, add the following to the
php.ini
file:I see that you tagged this with Ubuntu. Most likely the MySQL driver (and possibly MySQL) is not installed. Assuming you have SSH or terminal access and sudo permissions, log into the server and run this:
If the MySQL packages or the php5-mysql package are already installed, this will update them.
UPDATE
Since this answer still gets the occasional click I am going to update it to include PHP 7. PHP 7 requires a different package for MySQL so you will want to use a different argument for the apt-get command.
And importantly,
mysql_connect()
has been deprecated since PHP v5.5.0. Refer the official documentation here: PHP: mysql_connect()If you are getting the error as
Kindly login to the cPanel >> Click on Select Php version >> select the extension MYSQL
If someone came here with the problem of docker php official images, type below command inside the docker container.
For more information, please refer to the link above
How to install more PHP extensions
section(But it's a bit difficult for me...).Or this doc may help you.
(Windows mysql config)
Step 1 : Go To Apache Control Panel > Apache > Config > PHP.ini
Step 2 : Search in Notepad (Ctrl+F) For:
;extension_dir = ""
(could be commented with a;
). Replace this line with:extension_dir = "C:\php\ext"
(please do not you need to remove the;
on the beginning of the sentence).Step 3 : Search For:
extension=php_mysql.dll
and remove the;
in the beginning.Step 4 : Save and Restart You Apache HTTP Server. (On Windows this usually done via a UI)
That's it :)
If you get errors about missing
php_mysql.dll
you'll probably need to download this file from either the php.net site or the pecl.php.net. (Please be causius about where you get it from)More info on PHP: Installation of extensions on Windows - Manual
My guess is your PHP installation wasn't compiled with MySQL support.
Check your configure command (
php -i | grep mysql
). You should see something like'--with-mysql=shared,/usr'
.You can check for complete instructions at http://php.net/manual/en/mysql.installation.php. Although, I would rather go with the solution proposed by @wanovak.
Still, I think you need MySQL support in order to use PDO.