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", "[I]Username[/I]", "[I]Password[/I]", "[I]DB Name[/I]" );

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 [........]

Recommended Answers

All 10 Replies

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.

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.

The username/password combo is correct?

Member Avatar for diafol

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

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?

Member Avatar for diafol

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?

commented: Solved it! +3

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! :$

Member Avatar for diafol

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.

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 :)

Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.