Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


  Search this Thread
Old 06-28-2012, 08:40 PM   #1
LQ Newbie
Registered: Apr 2011
Location: Wellington
Distribution: Slackware
Posts: 8

Rep: Reputation: 3
php can't connect to mysql using Pear::MDB2

This is my first LQ post, but I've been using Slackware since around 2000.

A few days back I upgraded to -current (just before the most recent major update), which included httpd-2.4.2-i486-2 and php-5.4.3-i486-3. There were quite a few changes to httpd.conf, which I've integrated into my httpd.conf, but I can't get php to connect to the local mysql database using Pear::MDB2 any more.

The database is working fine, I can log in directly, and the webserver seems to be doing everything else right, but when connecting to mysql I always get
MDB2 Error: connect failed
I've upgraded from stable to the latest beta MDB2 library, but that didn't help:
MDB2              2.5.0b3 beta
MDB2_Driver_mysql 1.5.0b3 beta
I'm using the following as my connection string:
$db_options = array('debug'	=> 2);
$db =& MDB2::factory("mysql://${user}:${pass}@localhost/${db_name}", $db_options);
I've tried loading all the modules I could in httpd.conf, but to no avail, is there some other setting in httpd.conf I need to use to get this to work again? Can anyone give me any more pointers?

Old 06-29-2012, 01:50 AM   #2
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,545

Rep: Reputation: 136Reputation: 136
if you run
you may get an idea. Perhaps php is looking for the mysql socket in the wrong directory or something like that?

Hope this helps,
Old 06-29-2012, 07:55 PM   #3
LQ Newbie
Registered: Apr 2011
Location: Wellington
Distribution: Slackware
Posts: 8

Original Poster
Rep: Reputation: 3
Turned out the upgrade to php-5.4.3 meant that the old style mysql passwords (hashes of length 16) were being rejected by php (info found here). The fix was to reset the mysql passwords which rewrites the passwords with hashes of length 41. But first I needed to run mysql_upgrade to fix the privileges table.

[root@machine]$ mysql_upgrade -p
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/run/mysql/mysql.sock' 
Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/run/mysql/mysql.sock' 
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.user                                         OK
lots of other tables 
Running 'mysql_fix_privilege_tables'...
[root@machine]$ mysql -p
mysql> SELECT LENGTH(`password`) FROM mysql.user WHERE user=`user`;  # returns 16
mysql> SET PASSWORD FOR `user`@`localhost` = PASSWORD('blahblah');
mysql> SELECT LENGTH(`password`) FROM mysql.user WHERE user=`user`;  # returns 41
Problem solved.
2 members found this post helpful.
Old 06-29-2012, 08:03 PM   #4
Slackware Contributor
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 228Reputation: 228Reputation: 228
I'm sure I'll run into this with an upgrade I'm planning.

Thanks for posting your solution.
Old 06-29-2012, 08:05 PM   #5
LQ Newbie
Registered: Apr 2011
Location: Wellington
Distribution: Slackware
Posts: 8

Original Poster
Rep: Reputation: 3
Originally Posted by mRgOBLIN View Post
Thanks for posting your solution.
Glad to be of help - especially to a fellow kiwi!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pear: Cannot connect $db = &MDB2::connect($dsn) st0rmchaser Linux - Software 0 11-11-2011 11:55 PM
GameCP, MySQL, PHP Connect PHP to MySQL? armsman Linux - Software 1 09-15-2011 10:22 AM
Pear MDB2 - mapstorer fruitwerks Programming 0 04-16-2010 02:40 PM
can't connect php to mysql on RHEL5.0 in phpinfo page --without mysql is there vinayakbane Linux - Newbie 1 02-14-2009 11:47 PM
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 07:42 PM

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration