Jagboy Posted February 14, 2023 Share Posted February 14, 2023 I'm trying to get PHP8 to play nice with SQL, but only get the above error, when trying to create the mysqli object. All the code has been working fine for years on a Rapsberry Pi, but I've recently had to move to a NanoPi-R5C. PHP and SQL both work fine. phpinfo() says mysqli is installed, and it shows the correct library path and filename. I've also tried mysqlnd with the same result. I cannot figure out why it does not work. Any ideas? I've been stuck on this all day... Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/ Share on other sites More sharing options...
requinix Posted February 14, 2023 Share Posted February 14, 2023 Sounds like you don't have the mysqli extension installed or enabled... Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605629 Share on other sites More sharing options...
gizmola Posted February 14, 2023 Share Posted February 14, 2023 I have never seen a situation where an extension showed up in phpinfo and yet didn't work. It would also be helpful to know what OS you are running on the device. Is this a cli program or through a web server? If you run a simple script like this, what does it indicate? <?php if (function_exists('mysqli_connect')) { echo "mysqli is installed"; } else { echo "Enable Mysqli support in your PHP installation "; } Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605639 Share on other sites More sharing options...
gizmola Posted February 14, 2023 Share Posted February 14, 2023 One other detail: I'm not sure what you mean by "tried mysqlnd". You should use mysqlnd, but that is the client library that mysqli depends upon, and should appear in the mysqli section of phpinfo. The other option is to use the libmysqlclient from oracle. The default since php5.4 has been mysqlnd. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605640 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 18 hours ago, requinix said: Sounds like you don't have the mysqli extension installed or enabled... phpinfo() says mysqlnd in installed, and when I install msqli I get a similar display. AFAICT, there is nothing to do to "enable" it. If it's installed, it's enabled. Is there something I don't know (HIGHLY likely!!)? Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605688 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 (edited) 9 hours ago, gizmola said: I have never seen a situation where an extension showed up in phpinfo and yet didn't work. It would also be helpful to know what OS you are running on the device. Is this a cli program or through a web server? If you run a simple script like this, what does it indicate? <?php if (function_exists('mysqli_connect')) { echo "mysqli is installed"; } else { echo "Enable Mysqli support in your PHP installation "; } When I run your code snippet, it says "Enable Mysqli support in your PHP installation". HOW do I "enable Mysqli"?? Edited February 15, 2023 by Jagboy Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605689 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 9 hours ago, gizmola said: One other detail: I'm not sure what you mean by "tried mysqlnd". You should use mysqlnd, but that is the client library that mysqli depends upon, and should appear in the mysqli section of phpinfo. The other option is to use the libmysqlclient from oracle. The default since php5.4 has been mysqlnd. This is far from my area of expertise, so I may be completely misunderstanding things. My understanding is that mysqlnd is, effectively, a replacement for mysqli, which is basically API-compatible, so the same PHP script should run with either. Is my understandingn wrong? On the RPi-3B, which I was using until recently, I used mysqli and had no problems. Anyway, whether I install mysqli alone, without mysqlnd, or install my mysqlnd alone, without mysqli, when I run my PHP script using php-cli, I get: "Fatal error: Uncaught Error: Class "mysqli" not found...". I would be thrilled to find out I am just an idiot, and doing something stupid. That would be the best solution! Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605690 Share on other sites More sharing options...
maxxd Posted February 15, 2023 Share Posted February 15, 2023 I don't know what RPi-3B is and I'm not a SysAdmin but I will say the if you're starting a new project with no skin in the game, go with PDO over MySQLi. It's much easier to work with and (I think) enabled by default. (I think.) Either way, I know it's easier to deal with while coding. mysqli is not a direct corollary to the removed mysql_* functions so no matter what you're going to have to refactor a good amount of code. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605691 Share on other sites More sharing options...
kicken Posted February 15, 2023 Share Posted February 15, 2023 10 minutes ago, Jagboy said: when I run my PHP script using php-cli The CLI version of PHP can have a different configuration than the version you'd get with whatever http server you're using. You can check the modules loaded in the CLI version by running php -m or get full phpinfo like output using php -i. Use either of those to test if mysqli is enabled. php -m | grep mysqli If it's not enabled, you can find relevant configuration files with php -i | grep .ini Look at the INI files to determine how to enable mysqli for CLI. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605692 Share on other sites More sharing options...
requinix Posted February 15, 2023 Share Posted February 15, 2023 1 hour ago, Jagboy said: phpinfo() says mysqlnd in installed, and when I install msqli I get a similar display. mysqlnd and mysqli are not the same thing. Does phpinfo() specifically say that mysqli is there? Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605695 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 38 minutes ago, maxxd said: I don't know what RPi-3B is and I'm not a SysAdmin but I will say the if you're starting a new project with no skin in the game, go with PDO over MySQLi. It's much easier to work with and (I think) enabled by default. (I think.) Either way, I know it's easier to deal with while coding. mysqli is not a direct corollary to the removed mysql_* functions so no matter what you're going to have to refactor a good amount of code. RPi-3B is the RaspberryPi v3B board. On that version of this system, the OS is Debian Linux, while the new system (a NanoPi R5C) is running OpenWRT (another Linux variant). As I said, I truly hope I am simply doing someting stupid here. On the RPI3, I installed only the apache2 package, and the php-mbstring software package, and it just worked, as if by magic. I am not familiar wiith PDO. How different is it? I can re-write for PDO if I absolutely must. I did try running the script through the web server, rather than php-cli, but got the same result. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605696 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 1 hour ago, kicken said: The CLI version of PHP can have a different configuration than the version you'd get with whatever http server you're using. You can check the modules loaded in the CLI version by running php -m or get full phpinfo like output using php -i. Use either of those to test if mysqli is enabled. php -m | grep mysqli If it's not enabled, you can find relevant configuration files with php -i | grep .ini Look at the INI files to determine how to enable mysqli for CLI. php-cli -m | grep mysqli prints "mysqli". php-cgi does the same. I see nothing obvious in php.ini to enable php. The error message shows it does have the correct path for the mysqli library file. Numerous searches have reinforced my impresstion that simply installing the module should enable it, without changing anything in the ini file. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605697 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 24 minutes ago, requinix said: mysqlnd and mysqli are not the same thing. Does phpinfo() specifically say that mysqli is there? Yes, when it is installed, phpinfo() shows it is installed. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605698 Share on other sites More sharing options...
requinix Posted February 15, 2023 Share Posted February 15, 2023 Then you do have it installed. What code isn't working and what is the error message? Please make sure to copy and paste exactly what you have/see. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605699 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 1 hour ago, requinix said: Then you do have it installed. What code isn't working and what is the error message? Please make sure to copy and paste exactly what you have/see. See below files and screen shot . CommonDefs gets included into NewEvent. The first executable line in NewEvent is a call to connect in CommonDefs, which tries to create the mysqli object, which fails. Though now it is giving a different message (I don't know why?), the error is still at the same point in the code - the call to the mysqli constructor. CommonDefs.php.txt NewEvent.php.txt Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605701 Share on other sites More sharing options...
kicken Posted February 15, 2023 Share Posted February 15, 2023 (edited) That error is not Fatal error: Uncaught Error: Class "mysqli" not found, it's Quote Fatal error: Uncaught mysqli_sql_exception: No such file or directory Your mysqli extension exists and is working just fine, the error is because your connection is failing with a no such file or directory system error. My guess is this is due to mysql trying to use a unix socket to connect, but that socket does not exist. Mysql will try and use a unix socket instead of TCP when you specify 'localhost' as the hostname. Quote A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost Try changing the hostname in your connect call to 127.0.0.1 instead. Edited February 15, 2023 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605702 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 This looks like progress! Changing the host to 127.0.0.1 I get: Fatal error: Uncaught mysqli_sql_exception: Can't read dir of './qdtimerdata/' (errno: 13 "Permission denied") in /root/NewEvent.php:33 Stack trace: #0 /root/NewEvent.php(33): mysqli->query('SHOW TABLES;') #1 {main} thrown in /root/NewEvent.php on line 33 I assume this is a permissions problem in SQL? Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605705 Share on other sites More sharing options...
Solution kicken Posted February 15, 2023 Solution Share Posted February 15, 2023 3 hours ago, Jagboy said: I assume this is a permissions problem in SQL? Sounds like a permission problem with the directory where mysql stores it's database files. Seems like your mysql setup must have not be done properly (no unix socket, bad data dir permissions, who knows what else). Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605712 Share on other sites More sharing options...
Jagboy Posted February 15, 2023 Author Share Posted February 15, 2023 1 hour ago, kicken said: Sounds like a permission problem with the directory where mysql stores it's database files. Seems like your mysql setup must have not be done properly (no unix socket, bad data dir permissions, who knows what else). Thank you so much! I'm sure I can sort out the sql problem. I never would have figured out the localhost thing, without you pointing me in the right direction. What really surprises me is I had none of these problems when I set this all up on the Rapsberry Pi. I just installed the software, did some very simple configuration, and it all just worked perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605718 Share on other sites More sharing options...
gizmola Posted February 15, 2023 Share Posted February 15, 2023 Linux distros for the most part have their own package managers, and package developers who sometimes have schemes they are working with that differ from what another distro might use. Anytime you set up things on a different distribution you will likely encounter these differences and perhaps a problem or 2. I'm not sure why localhost wouldn't work, if you have a valid /etc/hosts file with an entry for it, but mysql also has a lot of potential configuration possibilities that change the behavior. By default it will use a unix socket, rather than trying to route through the network layer. Telling it to use 127.0.0.1 forces the client to try and use the network layer. This serverfault thread explores the issue and potential fixes. Quote Link to comment https://forums.phpfreaks.com/topic/315910-fatal-error-uncaught-error-class-mysqli-not-found/#findComment-1605732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.