Undefined function mysql_connect()

2019-01-01 04:02发布

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.

13条回答
爱死公子算了
2楼-- · 2019-01-01 04:40

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:

<?php
    phpinfo();
?>

If it's not there, add the following to the php.ini file:

extension=php_mysql.dll
查看更多
怪性笑人.
3楼-- · 2019-01-01 04:40

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:

sudo apt-get install mysql-server mysql-client php5-mysql

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.

sudo apt-get install mysql-server mysql-common php7.0 php7.0-mysql

And importantly, mysql_connect() has been deprecated since PHP v5.5.0. Refer the official documentation here: PHP: mysql_connect()

查看更多
初与友歌
4楼-- · 2019-01-01 04:40

If you are getting the error as

Fatal error: Call to undefined function mysql_connect()

Kindly login to the cPanel >> Click on Select Php version >> select the extension MYSQL

查看更多
只靠听说
5楼-- · 2019-01-01 04:42

If someone came here with the problem of docker php official images, type below command inside the docker container.

$ docker-php-ext-install mysql mysqli pdo pdo_mysql

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.

https://docs.docker.com/samples/library/php/

查看更多
君临天下
6楼-- · 2019-01-01 04:47

(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

查看更多
永恒的永恒
7楼-- · 2019-01-01 04:48

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.

查看更多
登录 后发表回答