Undefined function mysql_connect()

后端 未结 14 790
庸人自扰
庸人自扰 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:15

    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

    0 讨论(0)
  • 2020-11-22 11:18

    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

    0 讨论(0)
  • 2020-11-22 11:18

    For CentOS 7.8 & PHP 7.3

    yum install rh-php73-php-mysqlnd
    

    And then restart apache/php.

    0 讨论(0)
  • 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()

    0 讨论(0)
  • 2020-11-22 11:22

    The question is tagged with ubuntu, but the solution of un-commenting the extension=mysqli.dll is specific to windows. I am confused here?!, anyways, first thing run <? php phpinfo ?> and search for mysql* under Configuration heading. If you don't see such a thing implies you have not installed or enabled php-mysql. So first install php-mysql

    sudo apt get install php-mysql

    This command will install php-mysql depending on the php you have already installed, so no worries about the version!!.

    Then comes the unix specific solution, in the php.ini file un-comment the line

    extension=msql.so
    

    verify that msql.so is present in /usr/lib/php/<timestamp_folder>, ELSE

    extension=path/to/msql.so
    

    Then finally restart the apache and mysql services, and you should now see the mysql section under Configrations heading in phpinfo page

    0 讨论(0)
  • 2020-11-22 11:27

    Try:

    <?php
      phpinfo();
    ?>
    

    Run the page and search for mysql. If not found, run the following in the shell and restart the Apache server:

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

    Also make sure you have all the following lines uncommented somewhere in your apache2.conf (or in your conf.d/php.ini) file, from

    ;extension=php_mysql.so
    

    to

    extension=php_mysql.so
    
    0 讨论(0)
提交回复
热议问题