Markus1954 Posted December 28, 2021 Share Posted December 28, 2021 Hi All, I am trying to get the mysqli to work in a program i am copying from a book. I have removed the semicolon from the extension=mysqli. I also have extension_dir set to c:\php8\ext. I don't know what else to do. I am getting an error problem which is: Fatal error: Uncaught Error: Class "mysqli" not found in C:\Apache24\htdocs\Joy\createdb.php:6 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\Joy\createdb.php on line 6. Line 6 is the piece of code: $mysqli = new mysqli("mySQL", "USER", "p@SSWORD"); Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/ Share on other sites More sharing options...
Markus1954 Posted December 28, 2021 Author Share Posted December 28, 2021 By the way I am running php 8 on windows Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593040 Share on other sites More sharing options...
ginerjm Posted December 28, 2021 Share Posted December 28, 2021 And have you written this "mysqli" class and included it in your script? Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593042 Share on other sites More sharing options...
mac_gyver Posted December 28, 2021 Share Posted December 28, 2021 2 hours ago, Markus1954 said: I have removed the semicolon from the extension=mysqli. did you stop and start your web server to get any changes made to the php.ini to take effect? also, is the php.ini that you are changing the one that php is using (there's a loaded configuration... line in the phpinfo() output that states what file is being used.) the phpinfo() output will also list if/when the mysqli extension is being successfully loaded. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593043 Share on other sites More sharing options...
Markus1954 Posted December 29, 2021 Author Share Posted December 29, 2021 Yes, I went into services and restarted Apache. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593050 Share on other sites More sharing options...
maxxd Posted December 29, 2021 Share Posted December 29, 2021 Definitely check phpinfo() as mac_guyer recommended. Sometimes PHP uses an unexpected configuration file - check for both the Loaded Configuration File value and make sure that there's a full mysqli section in the output. Also, save yourself a ton of pain and switch to PDO now - it's much easier to deal with than mysqli overall. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593051 Share on other sites More sharing options...
Markus1954 Posted December 29, 2021 Author Share Posted December 29, 2021 Maxxd, This is what is loaded in my config file: Loaded Configuration FileC:\PHP8\php.ini I don't know how to use pdo_mysql. I do know that I have to go into the config file. Also I have mysqlnd in phpinfo(). Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593053 Share on other sites More sharing options...
ginerjm Posted December 29, 2021 Share Posted December 29, 2021 Are you running your own server(s) for this? Or do you have a host managing your PHP install? If the latter then you may already have pdo installed and using it is simply a matter of looking up PDO in the reference section and doing a little light reading and viewing the many samples. PDO is really the simple way of querying a db. $q = "select ........ where fld1=:arg1 and fld2=:arg2"; $qst = $pdo->prepare($q); $parms = array( 'arg1'=>"$myvalue1", 'arg2'=>"$myothervalue" ); if (!$qst->execute($parms)) { (handle an error condition for your user) } while($row = $qst->fetch(PDO::FETCH_ASSOC)) [ (handle a row of your results until all processed) } (move onto other logic) Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593055 Share on other sites More sharing options...
maxxd Posted December 29, 2021 Share Posted December 29, 2021 I haven't run PHP on windows in literally a decade or longer, so I'm not sure how much help I'm going to be. Do you have a section labeled 'mysqli` in the output from `phpinfo()`? You mention in your first post that you've updated C:\PHP8\ext, but your phpinfo is showing the config as C:\PHP8\php.ini - I know in Ubuntu there's an entire folder full of extension files - mine is at `/etc/php/8.0/mods-available` and includes files like `mysqli.ini`. As a bit of an aside, is this for production or development? If you're looking at a development setup on a windows machine I highly recommend either using WSL or Docker - preferably Docker, but it's not always an option (I'm typing this on my Surface tablet that can't handle Docker so I use local installs in WSL for dev). Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593060 Share on other sites More sharing options...
Markus1954 Posted December 29, 2021 Author Share Posted December 29, 2021 No, there is no section with the heading mysqli. C:\php8\ext has a lot of files in it. I have a file php_mysqli.dll. I also have a php_pdo_mysql.dll.. I am running a production environment. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593061 Share on other sites More sharing options...
maxxd Posted December 29, 2021 Share Posted December 29, 2021 (edited) OK, if there's no `mysqli` section in the output from phpinfo() then it's not enabled. Check your C:\PHP8\php.ini file and make sure the line `extension=mysqli.dll` doesn't have a semi-colon in front of it. Restart IIS and if that doesn't do it, then I'm sorry but somebody with more hands-on experience than I is gonna have to step in. Edited December 29, 2021 by maxxd typo Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593063 Share on other sites More sharing options...
ginerjm Posted December 30, 2021 Share Posted December 30, 2021 Should of noticed your use of "C:" and realized that you are running your own server. So I think you are getting good advice to getting your .ini file setup. I'll leave this topic to the pros. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593065 Share on other sites More sharing options...
Markus1954 Posted December 30, 2021 Author Share Posted December 30, 2021 the mysqli section does not exist. When I make chages to the php.ini file I restart Apache. Mysqli.dll does not have a semicolon in front or it. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593070 Share on other sites More sharing options...
mac_gyver Posted December 30, 2021 Share Posted December 30, 2021 (edited) are there any other extensions enabled in the php.ini that DO show up in the phpinfo output? check the web server's error log for any recent lines mentioning problems with loading the mysqli library/dll. also, delete and retype the mysqli in your line of php code in case it contains some non-printing or non-ascii characters, the result of copy/pasting, that are causing it to not be recognized by php. Edited December 30, 2021 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593073 Share on other sites More sharing options...
Markus1954 Posted December 30, 2021 Author Share Posted December 30, 2021 All of the following do not have a semicolon: bz2, mbstring, exif, mysqli, openssl, pdo_mysql. They are not listed in my phpinfo(). I noticed an error in my index.php file. It has this in it, <?php phpinfo(); ?> I got the err\or from the Apache error.log. I not see any mysqli errrors. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593083 Share on other sites More sharing options...
Markus1954 Posted December 30, 2021 Author Share Posted December 30, 2021 By the way doesn't mysqlnd have mysqli in it? Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593084 Share on other sites More sharing options...
mac_gyver Posted December 31, 2021 Share Posted December 31, 2021 it appears that php is not seeing or using the php.ini. there are a couple of common possibilities - the php.ini is actually named php.ini.txt, due to editing by a MS program, such as notepad.exe. have the file extensions been 'exposed' (a web search should show how to do this) on the computer, so that you actually see the whole filename.ext? when you browse to folders, do you see extensions like .exe, .txt. .dll? AFAIK, right-clicking on the php.ini and selecting 'properties' should show the actual full filename? if the php.ini is actually php.ini.txt, rename it to be just php.ini php doesn't report when there are syntax errors in .ini files, i.e. there is not a parse/syntax/reporting phase, just run-time errors for statements that fail when executed. how was php obtained and installed on the computer, i.e. has anyone else been editing the php.ini and could have introduced syntax errors in it? Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593085 Share on other sites More sharing options...
maxxd Posted December 31, 2021 Share Posted December 31, 2021 What error did you notice in your index.php file? Assuming the 'It has this in it,' is a copy/paste error and not actually in that php file, it looks fine (best practice is to leave off the closing php tag, but I don't think that has any bearing on your current issue). Please excuse me if this is a dumb question, but your comment about the error in Apache's log and mac_guyver's excellent point about the OS injecting file extensions got me thinking a couple things. You've tested that Apache itself is working, yeah? Like, you get the welcome page on a fresh site setup? Also, the page you're trying to serve via Apache has a '.php' extension? If you put the following code into the file 'testing.php' and the visit 'http://{yourdomain}/testing.php' you see 'Hello World!', right? <?php echo '<p>Hello World!</p>'; Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593088 Share on other sites More sharing options...
Markus1954 Posted January 1, 2022 Author Share Posted January 1, 2022 Apache is working and mysql is working. I rewrote the $mysql line and it did nothing. All my php files have a .php extension. Quote Link to comment https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/#findComment-1593106 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.