View Full Version : Unable to load dynamic library 'C:\php\ext\php_mysql.dll'

04-16-2011, 11:51 AM
Hi all,

I have a Windows 7 64-bit machine running Apache 2.2, PHP 5.2 and MySQL 5.5.

I've been following the steps on this site to get them all working together: http://www.bicubica.com/apache-php-mysql/index.php.

I get the PHP "It works!" page, and I can also create and query a table in command line SQL.

The problem is getting PHP and MySQL to work together.

I have added the following to the php.ini file:

LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "c:/windows"

extension=php_mysql.dll to the php.ini

extension_dir = "C:\php\ext"

session.save_path = "C:\WINDOWS\temp"

I have also added C:\php and C:\php\ext to my PATH system variable (tried adding it at the beginning AND at the end of the existing value).

I know I'm editing the correct php.ini file because I tested by changing the register_globals variable, restarting Apache and viewing info.php.

Here is what my Apache error log says:

[Sat Apr 16 10:39:10 2011] [notice] Parent: Received restart signal -- Restarting the server.
[Sat Apr 16 10:39:10 2011] [notice] Child 3084: Exit event signaled. Child process is ending.
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
[Sat Apr 16 10:39:11 2011] [notice] Apache/2.2.17 (Win32) PHP/5.2.17 configured -- resuming normal operations
[Sat Apr 16 10:39:11 2011] [notice] Server built: Oct 18 2010 01:58:12
[Sat Apr 16 10:39:11 2011] [notice] Parent: Created child process 6612
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysql.dll' - The specified module could not be found.
in <b>Unknown</b> on line <b>0</b><br />
[Sat Apr 16 10:39:11 2011] [notice] Child 6612: Child process is running
[Sat Apr 16 10:39:11 2011] [notice] Child 6612: Acquired the start mutex.
[Sat Apr 16 10:39:11 2011] [notice] Child 3084: Released the start mutex
[Sat Apr 16 10:39:11 2011] [notice] Child 6612: Starting 64 worker threads.
[Sat Apr 16 10:39:12 2011] [notice] Child 3084: All worker threads have exited.
[Sat Apr 16 10:39:12 2011] [notice] Child 3084: Child process is exiting
[Sat Apr 16 10:39:13 2011] [notice] Child 6612: Starting thread to listen on port 8080.
[Sat Apr 16 10:39:18 2011] [error] [client] PHP Fatal error: Call to undefined function mysql_connect() in C:\\Apache\\htdocs\\mysql_test.php on line 9

I've read loads of posts, and tried many solutions but I still can't get rid of that error. By the way, here is the page I'm trying to load:


# Define MySQL Settings
define("MYSQL_HOST", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASS", "password");
define("MYSQL_DB", "test");

$conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error());
mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());

$sql = "SELECT * FROM test";
$res = mysql_query($sql);

while ($field = mysql_fetch_array($res))
$id = $field['id'];
$name = $field['name'];

echo 'ID: ' . $field['id'] . '<br />';
echo 'Name: ' . $field['name'] . '<br /><br />';


Grateful any help!


Old Pedant
04-16-2011, 10:08 PM
Okay, so did you go look in the directory C:\php\ext???

Is the file php_mysql.dll in that directory????

04-17-2011, 01:30 AM
Yes it is!

Any other ideas?

Old Pedant
04-17-2011, 03:23 AM
Permissions, maybe?

Try making sure that the EVERYONE user has read/write permissions to that file (probably only needs READ, but won't hurt to give both).

04-17-2011, 11:02 AM
Still no luck. I found this thread which suggests it's actually another file, libmysql.dll which is causing the problem. But I've tried copying it into C:\Windows\System32, and I've tried editing my paths as I said.

Really frustrated - it's been 2 days now - anyone have any other suggestions?


04-17-2011, 03:35 PM
ok got it. If anyone is interested, I had to copy the libmysql.dll file into C:\Windows as well as into C:\Windows\System32.

I know, I know, I shouldn't copy library files straight into the System32 folder, but Windows wasn't picking it up, even when I put C:\PHP at the beginning of my PATH variable. What am I supposed to do?

Maybe it's a Windows 7 thing...

04-17-2011, 03:46 PM
Doing that is really a bad idea. You should be able to add the directory to the end of the path and have it work. You DID reboot after making that change right? Did you include a ; (semi-colon) after c:\php when you added it to the path?

Old Pedant
04-17-2011, 09:47 PM
Doing that is really a bad idea.

Why? Curiosity as to why you think it hurts anything.

Though I agree that it should have worked where it was.

04-18-2011, 12:02 AM
It's a Windows "system" directory and subject to change/removal/replacement at any time. Though the chances of the latter happening are small an update to MySQL that changes that DLL is likely going to cause the person grief if they don't remember that they put it there. It doesn't hurt anything per se, just likely to be a headache causer down the road.

Old Pedant
04-18-2011, 06:10 AM
Okay, those are the kinds of reasons I wouldn't do it. I thought maybe you meant it was harmful in some way. We are in violent agreement.