note 89464 added to function.mysql-connect
| From: | hugo at 1key dot nl | Date: | Mon, 09 Mar 2009 15:08:13 +0000 |
| Subject: | note 89464 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151656@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 89.248.170.61
Probable Submitter: 212.123.171.243
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/89464
Del: integrated -- https://master.php.net/note/delete/89464/integrated
Del: useless -- https://master.php.net/note/delete/89464/useless
Del: bad code -- https://master.php.net/note/delete/89464/bad+code
Del: spam -- https://master.php.net/note/delete/89464/spam
Del: non-english -- https://master.php.net/note/delete/89464/non-english
Del: in docs -- https://master.php.net/note/delete/89464/in+docs
Del: other reasons-- https://master.php.net/note/delete/89464
Reject -- https://master.php.net/note/reject/89464
Search -- https://master.php.net/manage/user-notes.php