Fatal error: Call to undefined function mysqli_connect()

前端 未结 14 993
面向向阳花
面向向阳花 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条回答
  •  萌比男神i
    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.

提交回复
热议问题