I know it is not the best practice but I am working on a site for a friend and I am trying to figure out a weird issue with PHP/MySQL. I try logging in as the user root (I know this is not recommended), and the root password, which are both stored in globals. I've had the following code which was working for several years, until one day it stopped work mysteriously.
I have double checked the contents of the globals, and the username/password/database defined in the globals are correct.
Howevere I get the following error:
PHP Code:
Could not connect: Access denied for user 'www-data'@'localhost' (using password: NO)
Is there any reason why when I try logging in as "root" it returns an error saying that I am trying to login as www-data without a password?
I have googled this for quite some time and the general result is either that I have run out of available connections from another PHP script not closing the mysql connecetion properly. However I have been unable to verify if that's the case here.
My guess is that at that point in the code, the variables you are using do not have any values, so it is trying to connect using the user name that is running your PHP script with no password. Thus one of the problems of depending on global variables.
But that's only a guess without doing some debugging to find out what the values are of those globals at that point in the code, then if not set (or wrong), tracing back through the code to see where they are defined or overwritten/unset.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
It certainly sounds like they are empty, since the default values come from the PHP config, which would explain the user name if $GLOBALS['dbUser'] were empty:
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
That is how I was displaying them however I did the echo statement(s) both in the if statement and I also printed them out at the very top, before I tried establishing the connection.
Uh-oh, sounds like somebody turned on sql.safe_mode on the web host.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Unless you have access to change the PHP system config (i.e. usually the php.ini file), I think you can override the values for the system defaults via ini_set().
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
mysql_connect will automatically re-use any open connections if available. You can force it to create a new one by adding true to the 4th argument.
So try:
Do you know the default location on linux for the php.ini file? I have server access.
This should tell you (look for the "Loaded Configuration File" line):
PHP Code:
<?php phpinfo(INFO_GENERAL);
Last edited by NogDog; 05-28-2012 at 09:47 PM.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks