Jump to content

Recommended Posts

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");
Link to comment
https://forums.phpfreaks.com/topic/314362-getting-mysqli-to-work/
Share on other sites

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.

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.

  • Great Answer 1

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)

 

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).

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 by maxxd
typo

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 by mac_gyver

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.

it appears that php is not seeing or using the php.ini. there are a couple of common possibilities -

  1. 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
  2. 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?

 

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>';

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.