Page 1 of 1

PHP Novice: Help!: Database connection from script

Posted: Fri Oct 08, 2004 9:51 pm
by sunnymix
hi. i've just started learning php and mysql. i can't seem to find out why the script can't connect to database

@ $db = mysql_pconnect('127.0.0.1', 'userid', 'password');

error message indicates it couldn't connect to database. i tried both my ip address, and localhost (as above) to no avail. is it something i have to configure from mysql database?

any help would be appreciated! thanks!

sunny

Posted: Fri Oct 08, 2004 10:55 pm
by LostMyLove

Code: Select all

$db = mysql_pconnect("localhost", "userid", "password");
should work

Posted: Fri Oct 08, 2004 11:40 pm
by sunnymix
thank you. i tried but i still have same connection error.

do you think my web server setting isn't correct? i'm not certain if mysql is on the server. i don't think my personal web server(apache) and mysql is connected properly. can u please suggest what i should do to change the configuration?

thank you!

Posted: Sat Oct 09, 2004 1:01 am
by feyd
there can be many things wrong:
username/password incorrect.
Wrong client version.
Wrong host address.
Wrong connection type.

what exactly does the error message say?

Posted: Sat Oct 09, 2004 1:46 am
by m3mn0n
add " or die ( mysql_error () )"

after the ) and before the ; in the function [php_man]mysql_pconnect[/php_man]() to get a more detailed error message.

Also, make sure there isn't a "@" in front of the function because that supresses any error messages.

Posted: Sat Oct 09, 2004 5:26 am
by twigletmac
You definitely need error handling for most database functions so that you can get much more useful error messages, as Sami said:

Code: Select all

$db = mysql_pconnect('127.0.0.0', 'userid', 'password') or die(mysql_error());
Mac

Posted: Sat Oct 09, 2004 12:48 pm
by sunnymix
thank you all for the replies!

this is what i wrote exactly...

$dbhost = '127.0.0.1'; //localhost
$dbuser = 'root'; //root as user id for sql server
$dbpass = '*****'; //password for the root

$db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to MySQL"); //this is where the script stops and issue "unable to connect to MySQL"

i also tried to put all the host and user information within parenthesis such as $db = mysql_connect('127.0.0.1', 'root', '*****'); also tried mysql_pconnect().

MySQL version is 4.1, version of php is 5.0.1, and i'm running apache server on windows xp. all of the installations were successful, and all of them runs just fine. i can do database works in MySQL shell, personal web server runs ok and i can parse php scripts without any errors. my firewalls are off also.

Posted: Sat Oct 09, 2004 12:51 pm
by sunnymix
i'm going to try "or die ( mysql_error () )" to see what is exactly the problem. thank you so much!!!

Posted: Sat Oct 09, 2004 12:55 pm
by sunnymix
thank you so much for the tip! i just ran die(mysql_error()); and this is what i received.

'Client does not support authentication protocol requested by server; consider upgrading MySQL client'

are there something else other than upgrading MySQL client to fix the problem?

Posted: Sat Oct 09, 2004 12:58 pm
by sunnymix
another silly questoin :) what do i need to download to upgrade MySQL client?

Posted: Sat Oct 09, 2004 4:56 pm
by feyd
[php_man]mysqli[/php_man] is what you should be using, I believe...

Posted: Sat Oct 09, 2004 10:44 pm
by sunnymix
thank you so much!. i've just found out how to fix that problem..phew! finally :)

because of new hashing algorithm for the password, the older version of my client api wouldn't get authorized with password i specified from the script. i did the following,

mysql> set password for 'staff(userid)'@'127.0.01(localhost)' = OLD_PASSWORD('*****');

and the script works fine now. i can select and insert data without any errors.

thanks!