Sunday, July 31, 2011

Quick detour into PHP

In this blog, we check out an error I'm getting in my online kanji learning program, at kanjisoft.com/lamp/fp. I did this as the final project for a course I took in PHP at Harvard Extension school, taught by the amazing David Malan. Btw, he and Daniel Armandez also teach a course in mobile programming, and it's available free online. Anyway, I had done this page as a final project, and I just moved it up to my site. But, someone wanted to check it out, and I logged into it and received this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'myname'@'localhost' (using password: YES) in /home4/kanjisof/public_html/lamp/fp/includes/functions.php on line 40
Could not connect to database Access denied for user 'myusername'@'localhost' (using password: YES)

So, let's see if we can figure out why access is getting denied. Probably the fastest thing to do is google it...

Ok, it looks like I might have an invalid password or username when I'm accessing in.

Let's establish what the username and password really are. Well, ok, first, let's look at the code and find out what we're trying to login as.

Ok, I'm on the server and here's the line:


if(($connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD)) === FALSE)

So, where is the name and password? It's not in this file. Let's go up a directory and grep it..

grep -ir DB_USERNAME *

There it is, we'll call it "myusername".

How about the password?

Ok, we'll call it "mypassword".

Ok. So, why does it say password is yes? Let's get into phpmyadmin...

Ok, I need to know what the database name is.

Here it is:

if(mysql_select_db(DATABASE_NAME, $connection) === FALSE)
{
exit( "Could not select database: " . mysql_error($connection) );
}

Ok, we know the drill. Back out and grep -ri DATABASE_NAME *.

Actually, it's likely to be where the other two were, in config.php.

Yup, it's my_databasename

Ok, now what?

Well, so the user name in my code doesn't match the current listed user, so that's probably the issue.

So, two questions - why did the username change, and why is it using password "Yes".

I think I'll call bluehost, they probably get this question a dozen times a day.

Ok, I'm on hold. ok, yeah, the username was the issue. it's strange, I didn't change anything, and the tech said they hadn't done anything on their end.

Anyway, it's all better. Check it out kanjisoft.com/lamp/fp. And that's a wrap :)

No comments:

Post a Comment