Jump to content

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


woozy

Recommended Posts

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.

Link to comment
Share on other sites

[!--quoteo(post=322108:date=Nov 25 2005, 09:12 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Nov 25 2005, 09:12 PM) 322108[/snapback][/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.

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

 = -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.

 

Link to comment
Share on other sites

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

 = -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)?

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.