Undefined function mysql_connect()

后端 未结 14 787
庸人自扰
庸人自扰 2020-11-22 10:56

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

Fatal error: Call to undefined

14条回答
  •  伪装坚强ぢ
    2020-11-22 11:20

    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()

提交回复
热议问题