Error: Uncaught Error: Class 'mysqli' not found

Asked

Viewed 3,631 times

1

I’m using Apache to make a site localhost, but I have an online bank and wanted to access it

I make the connection in php

<?php           
    $servername = "host.com";
    $username = "user";
    $password = "pass";
    $dbname = "banco";

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("connection failed: " . $conn->connect_error);
    }
?>

However when I go on the site it returns to me the following message

Fatal error: Uncaught Error: Class 'mysqli' not found in C: Apache24 htdocs folder index.php:133 Stack trace: #0 {main} thrown in C: Apache24 htdocs folder index.php on line 133

I tried to edit "php.ini-Development" and php.ini-Production in the PHP folder by putting extension_dir = "C:/PHP/ext" but it didn’t work

  • What version of PHP?

  • 2

    You’ve cleared the line extension=php_mysqli.dll? reinserted the apache?

  • Yes, I took ; out of the way in 2 php.ini ;On windows: extension_dir = "C:/PHP/ext"

  • Restarted (Restart) Xampp/Wamp/easyphp/apache after uncommenting?

  • @Guilhermenascimento I did the manual installation of Apache and Php, I didn’t use Xampp pq I couldn’t even turn on Apache for it

1 answer

1

The php.ini Apache is usually different from php.ini which they see in php, if you manually installed php and apache you must configure in httpd.conf the parameter PHPIniDir, assuming your php is in C:.

If it is PHP5:

LoadModule php7_module "C:/php/php5apache2_4.dll"
PHPIniDir "C:/php/php.ini"

If it is PHP7:

LoadModule php7_module "C:/php/php7apache2_4.dll"
PHPIniDir "C:/php/php.ini"

I believe that usually the dlls php5apache2_4.dll and php7apache2_4.dll see in TS version of PHP, I believe in NTS does not contain, but I am not sure (I will review this information).

Read more about TS and NTS on Thread Safe(TS) and Non Thread Safe(NTS) - What are they, what’s the difference?

Being Apache for Windows with Apache2handler you need to download the PHP Thread Safe on the link: http://windows.php.net/download/, if you already have php correct ignore this step.

If you know the way PHPIniDir "...." then look for it and edit the extensions ; the front of the line shall be similar to this:

extension=php_mbstring.dll
extension=php_exif.dll; Must be after mbstring as it depends on it
;extension=php_memcache.dll
;extension=php_mysql.dll
extension=php_mysqli.dll

So after this it is necessary to restart Apache, if installed manually will depend on the type of installation.

If you have no control panel but have installed as a service you can try the command:

cd C:\Apache24\bin
httpd -k restart

If it doesn’t work it’s because it’s not a service, then maybe you installed Apache Service Monitor, you can restart it for it:

Apache Service Monitor

If nothing goes right, then try to log out of windows, or restart windows.


For those who use Xampp can use the own dashboard, click Stop next to Apache and then click Start:

xampp

  • I think the problem is restarting Apache When I try to restart it, this msg appears. [Mon Aug 21 15:30:36.261743 2017] [mpm_winnt:error] [pid 4408:tid 440] (OS 2)O sistema nÒo pode encontrar o arquivo especificado. : AH00436: No installed service named "Apache2.4".

  • @Someone is because NAY is a service, I made it clear in reply: Se não funcionar é porque não é um serviço, então talvez tenha instalado o Apache Service Monitor, if it still doesn’t work, just restart Windows and try again.

  • Actually, I have Apache Service Monitor, but unlike this image you posted, it does not find any apache service

  • @Alguek how you start apache on your machine?

  • C: Apache24 bin and open httpd.exe This opens a DOS screen that is always black and I can’t type anything, but the server is online

  • @Alguek closes this DOS screen (cmd) and then runs again the C:\Apache24\bin\httpd.exe and then make sure mysqli is working. Don’t forget to check out Phpinidir on httpd.conf.

  • instead of PHPIniDir "C:/php/php.ini" placed 'PHPIniDir "C:/PHP/php.ini-production" and ALELUIAMENTE IT WORKED kkkkkk Thank you for everything and for having all that patience

  • @Alguek is because the php.ini this misconfiguration or does not exist.

  • It actually does not exist however came like this when I downloaded PHP on the site itself, by what I saw they took the ini and put 2 files the php.ini-development and php.ini-production

  • It doesn’t exist because you must create based on php.ini-development or php.ini-production. Just for the record php.ini-development is for development and php.ini-production is an example for when to publish online. @Alguek

  • Ah, I had to edit one of these 2 and create php.ini? Putz .

  • @Some if the machine that installed Apache+php is ONLY to develop a copy of php.ini-development and renamed the copy php.ini in php.ini extension=php_mysqli.dll, then configure phpinidir with php.ini, close CMD with Apache and open again. Ready should work 100%.

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.