php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #31418 MySQL connection functions do Not Work With Double Quotes on Argument
Submitted: 2005-01-05 16:46 UTC Modified: 2009-03-05 02:11 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sam dot boles at acfb dot org Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.0.3 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sam dot boles at acfb dot org
New email:
PHP Version: OS:

 

 [2005-01-05 16:46 UTC] sam dot boles at acfb dot org
Description:
------------
 Issue Environment:
Apache/2.0.52 (Win32) PHP/5.0.3 
MySQL client API version 4.1.7
MySQL version 4.1.7 -nt
Windows 2000 Server Service Pack 4

When trying to connect to MySQL database using either mysql or mysqli extensions, the server throws this error: Error 1045:Access denied for user 'user_name'@'host_name' (using password:YES).  (user_name and host_name in the previous error are actual user and host name in the real error message--these names have been changed to protect the innocent.)
 
This error occurs when connecting via PHP, does not occur when using other MySQL clients.  Almost all of the online documentation and examples I found use a syntax with double quotes on the arugments to the connection functions.  {$mysqli = new mysqli("host_name","user_name", "password", "database");}  It is this double quote syntax seems to be what caused the function not to work in above named environment. As far as I can tell, there are no escape characters or variable interpolations in the actual username, password or databse, so I don't belive that is the issue. Notwithstanding, changing the function arguments to single quotes {$mysqli = new mysqli('host_name' , 'user_name', 'password', 'database');} seems to work perfectly.

I have tested this pattern and it is very consistent--double quoted arguments will not work, single quoted arguments function smoothly. 

A mention of this in the docs or online resources would be helpful. 

This may be something unique to this configuration, or to my environment.  Also, if I am just blind and missed a mention of this in the documentation, please forgive.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-05 20:59 UTC] nlopess@php.net
This is very very strange.

What username/password are you using?? (or if you don't want to give the password, just say if you are using '\' or '"' chars in it.

Nuno
 [2005-01-05 21:07 UTC] sam dot boles at acfb dot org
Host is localhost
username is root 
password does not contain '\' or '"'--strictly alphanumeric
don't know if this makes any difference, but in the versions that don't work, when the error message prints, it puts both the username and hostname in single quotes

such as: 
Error 1045:Access denied for user 'root'@'localhost' (using password:YES)
 [2005-01-06 09:36 UTC] vrana@php.net
I can't believe that this is caused by any difference between ' and ". Is your code really so simple? Don't you use any variables or escape sequences inside strings?

Are you using new passwords or old in MySQL? You can check this by "SELECT Password FROM mysql.user WHERE Host = 'localhost' AND User = 'root'". If the password begin with * it's new otherwise it's old. MySQL extension doesn't work with new passwords (but with different error message), MySQLi does.

 [2005-01-06 19:23 UTC] sam dot boles at acfb dot org
The code listed is simple because I was taking this one step at a time.  I wanted to be sure I could attach to the DB before writing more complex code to actually do anything.  I did not want to put in the work at a full application until I knew that the motor would turn over, so to speak.

Here is the course of the issue, as it evolved:

I installed MySQl several months ago (upgraded to 4.1.7 when that was released) and have been using it via ASP using ODBC and also through the native MySQL clients successfully.  However, for portability reasons, want to migrate to the PHP scripting language and use the built in mySQL (or mySQLi) functions rather than ODBC.  So I installed Apache 2.0 and PHP 5.0.3 to gain this advantage.

However, what I found was that every attempt to do even the simplest things with mySQL via PHP were stymied by the fact that the function would not connect to the server--threw the 1045 error.

I tried several solutions--including updating the mysqllib.dll and modifying php.ini, my.ini and Apache configurations.  I tried setting the MySQL server to use only Old Passwords.  None of this had any affect on the ability of the script to even connect with the server.  Essentially, I tried every solution mentioned in various forums and help documents found on the PHP, MySQL and other sites.

I finally found one example online that used single quotes rather than double quotes on the function arguments.  When I tried using this syntax, PHP connected and continues to function correctly.  All queries issued using this connection format work perfectly.  Double quotes throw the error.

I'm sure that it must be something odd about my setup here, but since I saw several web posts mentioning trouble with this very issue, wanted to put it out as a tip for something others could try if they are having similar issues.

And I do use variables and escape sequences in strings.  What I meant (sorry I wasn't clear) is that there is nothing in the strings that comprise the actual username "root" or password "hoo25boy" (not the real password) that were formatted like escape sequences or variables and that could have been misinterpreted somehow by the PHP or MySQL engines.

I agree this is very very odd.  A simple change like going from 

$mysqli = new mysqli("host_name","user_name",
"password", "database");  

to

$mysqli = new mysqli('host_name','user_name',
'password', 'database');

shouldn't have affected this--but in test after test here it does. 


Thanks.
 [2005-01-07 09:13 UTC] vrana@php.net
> I saw several web posts mentioning trouble with this very
> issue.

Can you please give us links to these posts? There can be some clue to understand this problem.
 [2005-01-31 22:28 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2007-01-30 18:39 UTC] harvey at engineer dot com
Look in your ini file to set up quotes to work the way you want them to.  Also check the setting for 'magic-quotes'.
 [2009-03-05 01:24 UTC] privsman at gmail dot com
for the "password: yes" issue, you have to go to the terminal, then root@none, and allow the user in mysql access from there, and then set pass for the user there too.  You can't do it from PHPmyadmin, even with the masteradmin grant privs.
 [2009-03-05 02:11 UTC] philip@php.net
This report looks bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 07 11:01:31 2024 UTC