note 89464 rejected from function.mysql-connect by danbrown
| From: | danbrown@php.net | Date: | Mon, 09 Mar 2009 15:51:18 +0000 |
| Subject: | note 89464 rejected from function.mysql-connect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151657@lists.php.net to get a copy of this message | ||
Note Submitter: hugo at 1key dot nl
----
There seems to be some problem with mysql_connect and passwords between double quotes. Recently I
got this code for review as it failed with the commented error:
<?php
mysql_connect("localhost", "user_name", "p@ssw'ord") or die
(mysql_error());
/* Gives this error:
-- Access denied for user 'user_name'@'localhost' (using password: YES)
*/
?>
please note the special characters in the password. When you try to connect using this command you
get the error even though you can connect using phpmyadmin, commandline mysql etc.
When you change the double quotes to single quotes the problem is solved. It might be of interest to
those used to set strings in double quotes.
<?php
mysql_connect('localhost', 'user_name', 'p@ssw\'ord') or die
(mysql_error());
// Works perfectly
?>