PHP Fatal error: Uncaught Error: Class 'mysqli' not found in

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
Hi, I am trying to migrate to php 7.4 but when I switch to version 7.4 from the control panel, and I set the options
mysqlnd, nd_mysqli, nd_pdo_mysql so that I have activated access to mysql server I get the error:
Code:
 PHP Fatal error: Uncaught Error: Class 'mysqli' not found in
when I try to do:
PHP:
 $ this-> conn = new mysqli (DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
The same code works in PHP 7.2 on the server.

I have tried to change other versions like php 7.3, 7.4 and I get the same error, it only works fine for me on php 7.2 which is what I currently have.

In my local I have tested the code and it works fine in php 7.2 and php 7.4.24.

I have read in the forum other users with the same problem, it seems that the library is not installing correctly when changing the version of php.

Any solution? Thanks
 

kraitreuter

New Member
Messages
7
Reaction score
0
Points
1
i'm having that issue, on the php version selector i cant use wordpress with the default configuration, with the native version i can't install plugins on wordpress (beside the warnings of php version)... the wordpress installation seems to be good, but i can't change anything in it, neither install plugins.
 

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
Maybe it's a bug I understand from directadmin
Maybe a bug with the server/host your on. The connection test script is returning connected on x13.x10 host, to the account default $db. The username is different then the one stated in Directadmin.

Code:
$mysqli_connection = new MySQLi('localhost', 'user', 'pass', 'db');
if ($mysqli_connection->connect_error) {
   echo "Not connected, error: " . $mysqli_connection->connect_error;
}
else {
   echo "Connected.";
}
 
Last edited:

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
Tal vez un error con el servidor/host en el que está. El script de prueba de conexión regresa conectado en el host x13.x10, a la cuenta predeterminada $db. El nombre de usuario es diferente al indicado en Directadmin.

[CÓDIGO]$mysqli_connection = new MySQLi('localhost', 'usuario', 'contraseña', 'db');
if ($mysqli_connection->connect_error) {
echo "No conectado, error: ". $mysqli_connection->connect_error;
}
demás {
echo "Conectado.";
}
[/CÓDIGO]
I am on server x14, that code is similar to the code I use on my server.

I created a file called pruebas.php and put the code you provided.

If I run it with my current php 7.2 configuration, it returns connected, however, if I change in directadmin the php version to 7.3, 7.4 or 8 I get a 500 error.

Attached are some screenshots.

Trace error:
#0 {main}
thrown in /home/nokiajav/domains/nokiajavi.tk/public_html/pruebas/pruebas.php on line 2
2023-05-08 17:25:25.541972 [NOTICE] [4111834] [81.40.58.253:54959-1#APVH_www.nokiajavi.tk:lsapi] [STDERR] PHP Fatal error: Uncaught Error: Class 'MySQLi' not found in /home/nokiajav/domains/nokiajavi.tk/public_html/pruebas/pruebas.php:2
Stack trace:
#0 {main}
 

Attachments

  • Current_php7.2.JPG
    Current_php7.2.JPG
    15.6 KB · Views: 2
  • Change_php_7.4_or_8.0.JPG
    Change_php_7.4_or_8.0.JPG
    37.2 KB · Views: 2

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
I'm getting 404 for "pruebas.php". I noticed when changing the php version the mysqli ext. was not enabled (checked). I only went to php 8.0.
 

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
I deleted the file after testing because it has the parameters of bd for security, but if you want to do some test I leave it on to try.
 

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
If no direct link to error, then there is no error. www.nokiajavi.tk is active
If it is active because I make the change to test and then I leave it as it was because if I do not stop working the websites I have. When I change the version of php comes out the errors that I have mentioned, but I can not leave the website failing.
 

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
Yes I understand. So x10 free accounts are community support. I'm on x13, all php versions mysqli is active. I have it set to version 8.0 you can check my phpinfo file. tbint.us/phpinfo.php

If you have phpinfo in root directory it will update every time you change php version. Great for trouble shooting. php 7.4 should have no issues running mysqli. http://www.nokiajavi.tk/phpinfo.php.

Not even going into nd_mysqli or nd_pdo_mysql.
 

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
I have put the phpinfo.php in my root, to see the changes, I run with the current version 7.2 and when I search for the mysqli module with the browser search engine, I get 30 results, including a section of mysqli and another of mysqlli_nd.

However, when I switch to php 7.4 or php 8.0, I only get 2 results, the only thing that appears for mysqli is the Module Authors section:
MySQLi Zak Greant, Georg Richter, Andrey Hristov, Ulf Wendel

No table appears with mysqli as with the previous version, I attach the screenshots.

I have noticed that despite changing the version of php in directadmin, in the phpinfo I still get 7.2.34, it is very strange, maybe that's why the failure of not finding the modules, which fails to change the version for some reason and therefore not all modules are installed, as many more are missing.
 

Attachments

  • mysqliphp7.2.JPG
    mysqliphp7.2.JPG
    128.7 KB · Views: 4
  • mysqliphp7.2_other.JPG
    mysqliphp7.2_other.JPG
    138.2 KB · Views: 4
  • NO_mysqli_php_7.4.JPG
    NO_mysqli_php_7.4.JPG
    100.9 KB · Views: 4

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
x13.x10 with php version 7.4 >> https://tbint.us/phpinfo.php I'll leave it on 7.4 give you time to compare.

mysqli > enabled
mysqlnd > enabled

I get conflict enabling nd_mysql there is a notification at top have to scroll up to see it. Have to disable mysqli to get it to enable. Then the below script changes. mysqli connection test: bool(false)

You can check out the ext test, see they are working. https://tbint.us/file_get.php

Code:
<html lang="en">
  <head>
    <title>PHP Ext. test</title>
  </head>
  <body>
    <ul>
      <li><?php echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';?></li>
      <li><?php echo 'file_get_contents: ', file_get_contents(__FILE__) ? 'Enabled' : 'Disabled';?></li>
      <li><?php echo 'file_get_contents can connect to other websites: ', ini_get('allow_url_fopen') ? "Enabled" : "Disabled";?></li>
      <li><p>mysqli connection test: <?php var_dump(function_exists('mysqli_connect'));?></p></li>
      <li><p>GD Ext, Test:<br><?php var_dump(gd_info());?></p></li>
      <li><p>Imagick Ext. Test:<br><?php var_dump(function_exists('imagick'));?></p></li>
      <li><p><?php print_r(imagick::getVersion());?></p></li>
    </ul>
  </body>
</html>
 
Last edited:

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
I have copied the code to a test.php file on my website, plus I have included the phpinfo as well.

I changed to php 7.4 and disabled the modules mysqlnd,nd_mysqli,nd_pdo_mysql and then enabled the modules: mysqli and mysqlnd as you indicated, getting the same error.

When executing the code, it fails me after mysqli connection test, which also gives false.

I attach the screenshots. Thanks
 

Attachments

  • test.JPG
    test.JPG
    25.2 KB · Views: 3
  • configDirectAdmin.JPG
    configDirectAdmin.JPG
    101.2 KB · Views: 2

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
MySQL Native driver (mysqlnd) throws errors for nd_mysqli, and nd_pdo_mysql. So do you get error for your website with just these ext.
msqli
PDO
pdo_mysql
pdo_sqlite

You should know what database requirements your script needs, and figure out how to configure php version 7.4. The directadmin manage php version is like editing .user.ini. Any conflicts with your htaccess or your script.
 
Last edited:

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
You are right, I have cleaned up my php 7.2 installation, and checked the libraries I need, and left checked only: mysqlnd and nd_mysqli.

I have disabled pdo and pdo_sqlite.

My website is still working fine, everything is fine, I try the database access with:

$this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

Now I change to php 7.4 and I still get the error.
 

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
I have issues with my script every time I enable MySQL Native driver (mysqlnd), That includes nd_mysqli, and nd_pdo_mysql.

When I use MySQL Improved Extension: (mysqli) (sqlite) (pdo) (pdo_mysql) (pdo_sqlite) database connects. On php version 7.2, 7.4, 8.0.

As far as I can tell (nd_mysqli), and (nd_pdo_mysql) are the issues. at least in my case.
 

nokiajav

New Member
Messages
28
Reaction score
1
Points
3
If it seems uqe happens to me the same, but if I change to mysqli does not work the connection with the New mysqli, I do not know why this happens I will try to find out the cause. Let's see if I can change to mysqli and update the php. Thanks a lot
 

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
To use MySQL Native driver (mysqlnd); Disable (mysqli); Enable (mysqlnd) (nd_mysqli) (pdo) (pdo_dblib) (pdo_mysql) (pdo_sqlite).

In phpinfo file the mysqli section is active and the first line reads: Client API library version - mysqlnd 8.0.28

PDO allows comparatively seamless switching between different databases and
platforms, which can be easily done by changing the connection string. It does
not support database-specific syntaxes. The PDO extension can access any database
which is written for PDO driver.

In the phpinfo file you can see the support for different types of databases like PostgreSQL. In the PDO section the first lines reads: PDO drivers - dblib, mysql, sqlite.

My script still is able to connect to database.
 
Top