Undefined function mysql_connect()

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

    There must be some syntax error. Copy/paste this code and see if it works:

    <?php
        $link = mysql_connect('localhost', 'root', '');
        if (!$link) {
            die('Could not connect:' . mysql_error());
        }
        echo 'Connected successfully';
        ?
    

    I had the same error message. It turns out I was using the msql_connect() function instead of mysql_connect().

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

    (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

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

    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
    
    0 讨论(0)
  • 2020-11-22 11:14

    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.

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

    I was getting this error because the project I was working on was developed on php 5.6 and after install, the project was unable to run on php7.1.

    Just for anyone that uses Vagrant with ubuntu/nginx, in the nginx directory(/etc/nginx/), there is a directory named "sites-available" which contains a file named like the url configured for the vagrant maschine. In my case was homestead.app. Within this file there is a line that says something like

        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    

    There you can change the php version to the desired for that particular site.

    Googled this but wasnt really able to find a simple answer that said where to look and what to change.

    Hope that this helps anyone. Thanks.

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

    In php.ini file

    change this

    ;extension=php_mysql.dll
    

    into

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