tags:

views:

115

answers:

2

hi, i have a very strange problem, well not really a problem because i've fixed it but still, when i'm trying to connect to mysql db with:

mysql_connect("server", "user", "pass") or die(mysql_error());

im getting:

Access denied for user 'user'@'server' (using password: YES)

but when i change the quotes around the password to single quotes:

mysql_connect("server", "user", 'pass') or die(mysql_error());

it works just fine. i dont have this problem in another server i've got. so maybe it's something in the mysql settings or in the php.ini?

thanks.

+4  A: 

You must have a $ in your password.

That will cause php to interpolate a variable in the string.

You might also have an escape sequence, e.g., \t in your password which will cause similar problems.

Check out the manual for more info:

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing

webbiedave
(or \, or non-ascii chars)
symcbean
+1  A: 

Does your password contain any special characters like $? In double quotes PHP will try to interpret variables. Thus "My$Password" would yield in PHP looking for a variable called $Password, which isn't there. So the resulting password string will be simply My. (If you have enabled showing E_NOTICE errors you should get one.)

Furthermore special character sequences like \n are interpreted within double quotes.

nikic