Jump to content


Photo

PHP can not connect to mysql server, although other applications can


  • Please log in to reply
5 replies to this topic

#1 woozy

woozy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 November 2005 - 01:24 AM

I'm actually embarrassed to post this question because it is so general and vague but... well, I'm stumped

I recently had to reinstall PHP (4.4.1. for windows) and Mysql Server (4.1) and, well, I can't get a php connect and that is *all* I know.

I've written:

$db_user = 'webreader';
$db_password = 'w4reed';
$database = 'sirentiger';
$db_host = 'localhost';

$q = DB::connect("mysql://$user:$password@$host/$database");
if (DB::isError($q)){
die($q->getMessage();
}

And all I get is a simple message "DB Error: connect failed " And that's it! I've tried rewriting the connect command to use the root account and a variaty of other options.

I wouldn't feel so bad trying to debug but I'm not getting *any* response at all. Nothing shows up in the Web Server errer logs, nor in the MySql server error logs or anything. What can I do to trouble shoot? I don't have any idea why it's failing to connect and the message "DB Error: connect failed " is not very informative.

Any help appriciated!

Thanks.
--It was the devious-cruising Rachel, that in her retracing search after her missing children, only found another orphan.

#2 woozy

woozy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 November 2005 - 02:01 AM

Oops. I just notice my variable names don't match in the above post.

That *not* the problem. I still don't connect with the right variable names.
--It was the devious-cruising Rachel, that in her retracing search after her missing children, only found another orphan.

#3 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 26 November 2005 - 02:12 AM

Assign your database connection string to a variable, echo it, and let us know what the result is.

And I'm assuming that the DB library is installed by the way it generated the error.

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#4 woozy

woozy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 November 2005 - 03:02 AM

[!--quoteo(post=322108:date=Nov 25 2005, 09:12 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Nov 25 2005, 09:12 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Assign your database connection string to a variable, echo it, and let us know what the result is.

And I'm assuming that the DB library is installed by the way it generated the error.
[/quote]
I'm not sure what you mean by "connection string" but I rewrote to code as:

function get_db($host, $database, $user, $password){
require_once('DB.php');
$q = DB::connect("mysql://$user:$password@$host/$database");
echo "Database connection: $q<br>\n";
$q_array = get_object_vars($q);
foreach ($q_array as $k => $v){
echo "\$q[$k] = $v<br>\n";
}
echo (DB::connect("mysql://$user:$password@$host/$database"));
if (DB::isError($q)){
die($q->getMessage()." $user $password $host $database");}
return $q;

}

and it echoed out:

Database connection: Object
$q[error_message_prefix] =
$q[mode] = 1
$q[level] = 1024
$q[code=auto:0] = -24
$q[message] = DB Error: connect failed
$q[userinfo] = [nativecode=Can't connect to MySQL server on 'localhost' (10061)] ** mysql://webreader:reading@localhost/sirentiger
$q[backtrace] = Array
$q[callback] =
ObjectDB Error: connect failed webreader reading localhost sirentiger


I'm a bit confused by what the "10061" is supposed to mean. Is that a port number? If so it's the wrong one and I'm not sure where it got that number from. If so I guess that would be the first place to look. What do you think? Thanks for your help.

--It was the devious-cruising Rachel, that in her retracing search after her missing children, only found another orphan.

#5 woozy

woozy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 November 2005 - 03:44 AM

Oops again. The above result was when I had somehow turned of my MySQL service.

*This* is what I get

Database connection: Object
$q[error_message_prefix] =
$q[mode] = 1
$q[level] = 1024
$q[code=auto:0] = -24
$q[message] = DB Error: connect failed
$q[userinfo] = [nativecode=Client does not support authentication protocol requested by server; consider upgrading MySQL client] ** mysql://webreader:reading@localhost/sirentiger
$q[backtrace] = Array
$q[callback] =
ObjectDB Error: connect failed webreader reading localhost sirentiger

Soooooo, I guess I better look into authentication protocol and turning it off (or figuring out how to turn it on in php)?


--It was the devious-cruising Rachel, that in her retracing search after her missing children, only found another orphan.

#6 woozy

woozy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 November 2005 - 04:04 AM

Cool. Solved it!

This'll be an issue with MySQL 5 but seems to also be an issue with MySQL > 4.1 (I'm using 4.4.1)

MySQL changed the password hashing method from 16 byte to 32 byte encryption. DB.php doing the mysql::user:password@host, uses the old 16 byte encryption.

What I did was change the password in MySql using the OLD_PASSWORD() (as opposed to PASSWORD()) function, and change my password to be less secure but PHP compatible.

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/old-client.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/old-client.html[/a] has all the answers.

Thanks for pointing me in the right direction!
--It was the devious-cruising Rachel, that in her retracing search after her missing children, only found another orphan.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users