LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   php can't connect to mysql using Pear::MDB2 (https://www.linuxquestions.org/questions/slackware-14/php-cant-connect-to-mysql-using-pear-mdb2-4175413929/)

dr.trev 06-28-2012 08:40 PM

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
Code:

MDB2 Error: connect failed
I've upgraded from stable to the latest beta MDB2 library, but that didn't help:
Code:

MDB2              2.5.0b3 beta
MDB2_Driver_mysql 1.5.0b3 beta

I'm using the following as my connection string:
Code:

$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?

Cheers,
Trevor.

j-ray 06-29-2012 01:50 AM

if you run
phpinfo()
you may get an idea. Perhaps php is looking for the mysql socket in the wrong directory or something like that?

Hope this helps,
J

dr.trev 06-29-2012 07:55 PM

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.

Code:

[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'...
OK
[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> FLUSH PRIVILEGES;
mysql> SELECT LENGTH(`password`) FROM mysql.user WHERE user=`user`;  # returns 41

Problem solved.

mRgOBLIN 06-29-2012 08:03 PM

I'm sure I'll run into this with an upgrade I'm planning.

Thanks for posting your solution.

dr.trev 06-29-2012 08:05 PM

Quote:

Originally Posted by mRgOBLIN (Post 4715417)
Thanks for posting your solution.

Glad to be of help - especially to a fellow kiwi!!


All times are GMT -5. The time now is 09:29 AM.