MySQL extension not loading

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

MySQL extension not loading

Post by qwasqaws »

Yallo, I keep getting errors pertaining to the MySQL extensions not having been loaded. I've set up Apache, PHP and MySQL following a step by step tutorial and everything else worked fine. I looked around the net for the solution and did everything I could find and nothing worked. The extension line is uncommented in php.ini, the correct php.ini is being loaded, the extensions directory is correct and the windows PATH settings are correct. I'm new to the whole thing but I don't see what else it could be.

I have PHP 5.1.4 and MySQL 5.0.21.

Thanks in advance.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

What specific errors are you getting? Can you connect to MySQL via command line vs PHP?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Which mysql library are you trying to use, mysql or mysqli?
qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

Post by qwasqaws »

Commandline seems to work fine.

Code: Select all

<?php
mysql_connect('localhost', 'root', '****');
mysql_select_database('mysql');
mysql_query('SELECT * FROM `user`') or die('Could not execute query: ' . mysql_error());
?>
Gives me:
Fatal error: Call to undefined function mysql_connect() in H:\web\public\index.php on line 2

Trying to load phpmyadmin gives me:
Cannot load mysql extension. Please check your PHP configuration. - Documentation

I don't know what MySQLI is so I'll assume that it's the basic MySQL.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: MySQL extension not loading

Post by RobertGonzalez »

qwasqaws wrote:The extension line is uncommented in php.ini, the correct php.ini is being loaded, the extensions directory is correct and the windows PATH settings are correct. I'm new to the whole thing but I don't see what else it could be.
phpinfo() should tell you (right up at the top) what extensions are being loaded. Look for mysql or mysqli in that section. As of right now, there is either an uncommented php.ini extension line, there is no extension in the PHP\ext folder, or the path is wrong. Those are the usual things that report a call to an undefined function error.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Aside from what Everah mentioned, did you restart Apache after editing php.ini?
qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

Post by qwasqaws »

It doesn't say anywhere what extensions are loaded. What section should that be under? Theres no sqli anywhere so it must be sql.
I'm sure all the paths are correct. I even copied and pasted them to make sure I wasn't somehow overlooking a spelling error.

These are the lines in php.ini:

Code: Select all

extension_dir = "H:\web\PHP514\ext"
extension=php_mysql.dll
This is the link to the file:
H:\web\PHP514\ext\php_mysql.dll

All c+p'd. I even tried putting all the backslashes as forwardslashes. And yes, I restarted it after every change I made.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do a system search for php.ini. On my windows system I have like seven different php.ini files. See how many there are in your system.
qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

Post by qwasqaws »

The only one I have is in the windows directory and phpinfo says that's the one it's reading.
php.ini-dist and php.ini-recommended are in the php folder but they're meant to be there right?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So that means that you should have php.ini, php.ini-dist and php.ini-recommended in your windows directory. Inside of the PHP folder, there should be a folder called \ext. Inside of that folder should be a file called php_mysql.dll or php_mysqli.dll. Whichever one is there is the line in your php.ini file that you need to uncomment.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I've been helping him on MSN and it seems to all look OK to me. He's put the mysql .dll file in his ext folder and I don't think there is any need to copy php.ini dist and recommended anywhere, I think they are just dummy files incase you don't want to edit too much in your real php.ini.

He forgot to mention the MySQL service is running in services.msc too, not that I think that would cause the problem - I always thought call to undefined function errors were extension troubles.

He asked me earlier is there any config files which should point to the MySQL folder and I couldn't remember, maybe that could be the cause.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

There should be anything to do with config files unless you are changing mysql server start up variables. There's another thread going around on these forums in which a fellow has uncommented requested extensions in php.ini but still is having problems loading the extensions. I wonder if this guys problem was similar.

As long as his issues have been worked out, I supposed we should all be happy. :D
qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

Post by qwasqaws »

Just doing some testing I uncommented some other extensions and they all appeared in phpinfo() except... I don't know if this means anything but when I uncommented all the sql related ones, msql, mssql, pgsql and sqlite and the only one that showed up in phpinfo() was pgsql. So how come it's just not loading them? It's obviously in the right directory and the lines are uncommented. What more does it need?
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Have you got the following lines uncommented in your php.ini?

Code: Select all

// MySQLi extension
extension=php_mysqli.dll
I seem to remember reading somewhere that from a certain version of mySQL, you need to use the mysqli.dll extension.
qwasqaws
Forum Newbie
Posts: 8
Joined: Tue May 30, 2006 5:42 pm

Post by qwasqaws »

Same outcome as php_mysql. Doesn't work or appear in phpinfo. This is rather baffling.
Post Reply