Fatal error: Call to undefined function mysqli_connect()

前端 未结 14 780
面向向阳花
面向向阳花 2020-11-22 14:48

For 2 days now I\'m trying to solve this, but unfortunately no result. Let me tell you my story about the problem. I\'ve bulid an application on a site, and the application

相关标签:
14条回答
  • 2020-11-22 14:55

    Happens when php extensions are not being used by default. In your php.ini file, change
    ;extension=php_mysql.dll
    to
    extension=php_mysql.dll.

    **If this error logs, then add path to this dll file, eg
    extension=C:\Php\php-???-nts-Win32-VC11-x86\ext\php_mysql.dll

    Do same for php_mysqli.dll and php_pdo_mysql.dll. Save and run your code again.

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

    I followed below link to fix this problem. Make sure to enable following Module.
    php -r 'phpinfo();' | grep -i mysqli
    Link : https://askubuntu.com/questions/773601/php-mysqli-extension-in-ubuntu-16-04-not-working-after-upgrade-to-version-7-0-6

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

    Late to the conversation...

    If you have the module installed and set your PHP.INI file properly, check your apache error log for something like the following:

    PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysqli.dll' - The specified module could not be found.

    In this case, your extension directory is not what you think it is. You may neeed to set it explicitly, like so:

    extension_dir="C:\xampp\php\ext"
    
    0 讨论(0)
  • 2020-11-22 15:00

    If you host the server yourself, in the php.ini file remove the semicolon in front of the extension extension=php_mysqli.dll

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

    So this may not be the issue for you, but I was struggling with this error. I discovered what was causing my problem, though I can't really explain as to why.

    For me, mysqli_connect was working fine where the connection was made on pages in any various sub-directory. For some reason though, the same code referenced on pages in the root directory was returning this error. The strange thing is that it was working fine on my localhost environment in MAMP in the root directory, however on my shared host it was not.

    After struggling to figure out what was giving me "Error 500" white screen from this "PHP Fatal Error," I went through the code and stumbled upon this code in the error handling that was suggested by the PHP Manual (https://www.php.net/manual/en/mysqli.error.php).

    if (!mysqli_query($link, "SET a=1")) {
        printf("Error message: %s\n", mysqli_error($link));
    }
    

    I randomly decided to remove it and, voila, connection to the database working in root directories. Maybe someone smarter than me can explain this, for anyone struggling with a similar issue.

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

    Mysqli isn't installed on the new server. Run phpinfo() to confirm.

    <?php 
    
    phpinfo();
    
    0 讨论(0)
提交回复
热议问题