Jump to content

[SOLVED] Frustrated by - Cannot load mysql extension. Please check your PHP configuration


Recommended Posts

I am a relative newcomer to setting up a server, but I am by no means stupid and can follow instructions reasonably well, especially when written in an understandable form; and if I don't understand something then I google it to find the relevant information.

 

I am trying to set up Apache, MySQL, PHP and PhpMyAdmin on my laptop in order to be able to work away with stuff whilst travelling. Now everything works well until it comes to the final stage - PhpMyAdmin... All I get from PhpMyAdmin is:-

 

Cannot load mysql extension. Please check your PHP configuration.

 

I have trawled many websites and forums looking for an answer and have found not one that doesn't tell me to do what I have already done: uncomment the relevant extensions, ensure the extension_dir is correctly entered in the php.ini file etc. etc. As I say I am not stupid and worked all of this out before I started, it's called forward planning; but still I get this bloody stupid error message and can't for the life of me work out what the hell is wrong...

 

FYI I am using:-

 

Apache 2.2_9

MySQL 5.0.5

PHP 5.2.6

PhpMyAdmin 2.11.7

 

HELP!!!!!

Link to comment
Share on other sites

Check your web server error log file for any related messages. If there is a message about not being able to load the mysql dll, then the problem is as follows -

 

There is at least one auxiliary .dll that the mysql extension uses. The best method to get it to be accessible is to add the path to your php folder to the Windows PATH statement (re-boot your computer or re-logon as yourself to get any changes made to the Windows PATH statement to take effect.)

 

If there are no mysql related messages in the error log, then you need to make sure that the php.ini that you are changing is the one that php is using. Also, stop and start your web server to get any changes made to php.ini to take effect.

Link to comment
Share on other sites

Ok,

 

I checked the Apache error log and everything there seems to be fine, no mention of any mysql related errors at all...

 

The php.ini file I am using is the one that came in the .zip file (php.ini.recommended) and which I duly renamed php.ini, then modified as per the instructions in the PHP Documentation...

 

I have also just tried replacing the libmysql.dll as was suggested on one website I looked at, but this also has had no effect whatever.

 

Baffled ???  ???  ???

Link to comment
Share on other sites

Does the mysql_* functions work fine in a standalone script: eg:

<?php

echo 'Connecting to MySQL server...';

mysql_connect('localhost', 'root', '') or die(' FAILURE!<br />Error: ' . mysql_error());

echo ' SUCCESS!<br />';

echo 'Selecting \'mysql\' Database...';
mysql_select_db('mysql') r die(' FAILURE!<br />Error: ' . mysql_error());

echo 'SUCCESS!<br />MySQL extension is loaded and working fine';

?>

If the above code display errors, such as undefined function mysql_connect, or all you get is Connecting to MySQL server... and nothing else is displayed then the mysql extension is not loaded.

 

There could be many reasons why this could be. The first thing to do is to see of PHP is actually using the php.ini that you are edting, to test this simply run the phpinfo() function within a script, then run the script. Next Search for a line that starts with Loaded Configuration File. To the right of that line will be the full path to the php.ini PHP has loaded for configuration. If no path is stated then PHP is not reading the php.ini you are editing and thus PHPMyAdmin is displaying the above error.

 

To fix this, do as PFMaBiSmAd said, add PHP to the PATH Environment Variable. After doing this restart Windows. After Windows has booted rerun the phpinfo script and check to see if the php.ini has loaded.

 

Also avoid moving files outside of the PHP installation folder, this can cause more problems then needs be - especially when you upgrade PHP later on.

Link to comment
Share on other sites

Nice one, I hadn't thought of checking the it is possible to connect to MySQL...

 

Unfortunately this does not seem to be the solution, the connection to My SQL seems fine all I get is the error|:-

 

Parse error: syntax error, unexpected T_STRING in C:\server\Apache2\htdocs\mysql.php on line 10

 

which is this line:-

 

mysql_select_db('mysql') r die(' FAILURE!<br />Error: ' . mysql_error());

 

still baffled (but at thisn time it may be alcohol, so I will trey again in the moprning)

Link to comment
Share on other sites

I did say that the result was probably alcohol related, I didn't even spot the typo...

 

I just tried again with this result:-

 

Connecting to MySQL server...

Fatal error: Call to undefined function mysql_connect() in C:\server\Apache2\htdocs\mysql.php on line 5

 

Which is :-

 

mysql_connect('localhost', 'root', '******') or die(' FAILURE!<br />Error: ' . mysql_error());

 

So I assume that php is not making the connection due to not loading the extension.

 

Loaded Configuration File = C:\server\php\php.ini

 

and it is till in the php directory, I had read elswehere that moving it could cause problems, so I didn't

 

Looking for a suitable brick wall to bang head against!

Link to comment
Share on other sites

Have you added the PHP folder to the path environment variable, which was suggested earlier.

 

If its still doesn't load the extension, then PHP is most probably having difficulty finding the libmysql.dll library, which is required in order for the mysql extension to function. The libmysql.dll should be located in the root of your PHP folder. PHP should be able to find this file if PHP is added to the path environment variable.

 

Make sure you don't have any files such as php_mysql.dll or libmysql.dll outside of the php folder, check in places such as C:\Windows, C:\Windows\System32 etc. If you find any remove them as they will interfere.

Link to comment
Share on other sites

The one thing I had missed was adding my php folder to the path environment - is now done...

 

Have made sure that the libmysql.dll is in the root of my php folder - it is...

 

Have also checked for rogue .dll files and found none at all...

 

Net Result = phpMyAdmin still returns:-

 

Cannot load mysql extension. Please check your PHP configuration.

 

Maybe I should just throw myself under a passing bus!

Link to comment
Share on other sites

Ensure you have restarted Windows after modifying the PATH. Also clear your browsers cache too, incase your browser is loading an older page.

 

Make sure you have uncommented the correct extension, within the php.ini PHP5 comes with two extensions for mysql. These being php_mysql.dll and php_mysqli.dll

 

PHPMyAdmin can be configured to work with either extension. However the default is php_mysql.dll

 

Also when you installed PHP what media did you use? If you used the installer then I recommend you to go to php.net and download the zipped binaries package. Extract the contents of the zip to where PHP is currently installed to, overwriting existing files/folders. The installer comes with limited files.

Link to comment
Share on other sites

Modified PATH did a restart - check

 

Cleared browser cache - check

 

Checked once more that I uncommented the right extensions in php.ini - check

 

Installed php from zipped binaries package (as am aware installer is rubbish) - check

 

Net Result = No Change

 

PHPMyAdmin can be configured to work with either extension. How??? Just to check I have not made a booboo there...

 

Or perhaps it would be as well to go back to the drawing board and begin from the beginning, wiping out all of the files in the process before re-installing everything...

 

GRRRRRRRRRRRRRR!!!!!

Link to comment
Share on other sites

I was going to suggest a folder/files permission problem, but there would be an error in the error log about not being able to load the extension or there would be an actual permission error message in the error log.

 

Here is everything (off of the top of my head) that needs to be in place for the mysql extension to work -

 

Php needs to be loading the php.ini that you are changing.

 

php.ini needs an extension_dir = setting that points to where the main extension .dll files are located.

 

php.ini needs to have the line extension=php_mysql.dll uncommented.

 

The php_mysql.dll needs to be present in the folder pointed to by the extension_dir = setting in php.ini

 

The auxiliary libmysql.dll file that mysql uses needs to be in a folder that is on the Windows PATH statement.

 

All the .dll files need to be of the same version.

 

Stop and start your web server to get any changes made to any of the above items to take effect.

 

Is the basic mysql_connect php code working or still giving the undefined function message? Get that to work before worrying about phpmyadmin.

Link to comment
Share on other sites

PFMaBiSmAd: Have done all of those things with a net result of 0!

 

Have attached the output of phpinfo()

 

That passing bus is beginning to look more and more inviting...

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Well bugger me backwards with a big stick!!!!!

 

GENIUS

 

I looked at that several times and had convinced myself that it was OK - a simple case of not seeing the wood for the trees!

 

Looks like I don't need to throw myself under that bus after all - I might just open a bottle of cold white...

 

Thanks everyone for the help, especially the genius that is wildteen88... ;D ;D ;D ;D ;D

Link to comment
Share on other sites

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.