tags:

views:

333

answers:

5

I am having some strange issues with mysqli connections.

I was working on a page with mysqli, and it has been working fine all day. I then made a copy of this page, and stripped it down to debug a problem, and tested it as a different file. It worked fine connection wise. Upon trying to request the original file I was working on, I get the error:

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

I don't understand why. I have closed the connections after I have finished using them each time, although I don't see why that would be an issue. Interestingly, an older version of the file works fine, despite containing the exact same connection details and code.

What is going on?

A: 

Weird. If you are testing files from the same machine they should be working (if they have same code).

Check again username & password, i.e. spaces or strange chars.

Alekc
+2  A: 

Turn the question around. Rather than saying the two versions (the one that works and the one that doesn't) are identical in the aspects that matter, focus on the ways in which they are different and try to isolate which difference(s) also matter.

Make an additional copy of the working version. Verify that it works. Try making it into a copy of the non-working version by applying as many of the changes as you can, one by one, to this test copy, until you have something that is as close as possible to the broken version but that still works. Compare these two, and that should show you where the problem is.

MarkusQ
Well, if I copy the contents of the first file, into the second file x.php, it works fine. Just not from the first file.
Joshxtothe4
WTF? That's very strange.
MarkusQ
A: 

Just for the sake of it, run a diff between the working copy and older version of the file. Check for any issues like: moved brackets, variable name changes, etc. Maybe the part of the code that defines the username and password never gets run!

If you need a free program for that, check WinDiff

St. John Johnson
They are identical.
Joshxtothe4
Is the ENTIRE file identical? Do you want to post your code?
St. John Johnson
A: 

If you put:

error_reporting(E_ALL);

as the first line in your code do you get any errors on either page? There may be something strange like the program can't open an include file anymore.


You said copying File A to File B means File A doesn't work. What happens if you copy File A to File B, delete File A then copy File B to File A?

A: 

Ensure that your IP is added to the MySQL allowed connections list, also ensure your password is correct. Try providing a full hostname rather than localhost if possible.

Post your code if un-successful.