954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Access Denied Errors?

I recently moved a script I created for Google Maps over from my development site and I changed the information in the mysqli line and now I'm recieving an error mesage -- any idea what's going on here? Here's the error message:

Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'Username'@'localhost' (using password: YES) in /home/cigardig/public_html/XXXX.php on line 259


Here's the relevant code:

$mysqli = new mysqli(  "localhost", "<em>Username</em>", "<em>Password</em>", "<em>DB Name</em>" );


I also don't know if this has anything to do with it but this script is using stored functions which grant as follows:

/*!50003 CREATE DEFINER=`root`@`localhost` FUNCTION `BlahBlah`(Lat1 FLOAT, Long1 FLOAT, Lat2 FLOAT, Long2 FLOAT) RETURNS float [........]
jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

I forgot to mention in the previous post, the only thing that has changed was the username, password, and DB selected between the code. When I change it back to the old values it works but when I try the new ones it stops working again and generates the message.

jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

You have changed old database credentials to new.
Check your new database's credentials proper.I think it should not be username:root for host:localhost.
Something went wrong with credentials only.

vibhaJ
Posting Shark
931 posts since Apr 2010
Reputation Points: 161
Solved Threads: 183
 

The username/password combo is correct?

jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

May very well be you SP. Can you access DB w/out SP?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
May very well be you SP. Can you access DB w/out SP?

I can access it through PHPmyAdmin, Remote mySQL, as well as as on other pages - is that what you're talking about?

jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

php.net gives this example:

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');


I realise you don't want to post your actual settings, but do they match this format? They seem to from your post.

I think a typical default setting could be:

$mysqli = new mysqli('localhost', 'root', '', 'yourdbname');


phpmyadmin doesn't depend on you specifying a host, so it may be down to your host details. I assume your username and pw will be correct if you can use them to log in to phpmyadmin.

Perhaps it's the db name? Check spelling closely - no spaces. Underscores or dashes could be confused?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

php.net gives this example:

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

I realise you don't want to post your actual settings, but do they match this format? They seem to from your post.

I think a typical default setting could be:

$mysqli = new mysqli('localhost', 'root', '', 'yourdbname');

phpmyadmin doesn't depend on you specifying a host, so it may be down to your host details. I assume your username and pw will be correct if you can use them to log in to phpmyadmin.

Perhaps it's the db name? Check spelling closely - no spaces. Underscores or dashes could be confused?

Ugh, I feel like an idiot! I was using double quote instead of single quotes, changing that fixed and it's working beautifully now! :$

jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

Hi j. I have no idea wny this should happen. I tried it with both just now and both worked file. Perhaps you had a $ or \ or something weird in one of the strings?

Anyway, something I'll look out for. Thanks.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Hi j. I have no idea wny this should happen. I tried it with both just now and both worked file. Perhaps you had a $ or \ or something weird in one of the strings?

Anyway, something I'll look out for. Thanks.

ardav, you are right on. I had a $ in the password and it was parsing it weird as a result :)

jrotunda85
Junior Poster
144 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
 

Ahh. It's so good to be me sometimes... :)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: