Jump to content

Access denied for user 'ODBC'@'localhost'


bnther

Recommended Posts

That usually indicates you have either the username or the password wrong when you are trying to connect to the database. That's the first place I'd look when trying to fix this error.

 

I imagine that "ODBC" is the username you are trying to use, but I don't know what code you are working with.

 

Keep in mind that -- assuming you are either working with MAMP (Mac only) or WAMP (Windows only) -- the default username/passwords change. This could be an issue if the tutorial shows how to do things using WAMP but you're using a Mac, for example.

 

The defaults for MAMP:

username: "root"

password: "root"

 

The defaults for WAMP:

username: "root"

password: "" (blank - no password)

Link to comment
Share on other sites

That usually indicates you have either the username or the password wrong when you are trying to connect to the database. That's the first place I'd look when trying to fix this error.

 

I imagine that "ODBC" is the username you are trying to use, but I don't know what code you are working with.

 

Keep in mind that -- assuming you are either working with MAMP (Mac only) or WAMP (Windows only) -- the default username/passwords change. This could be an issue if the tutorial shows how to do things using WAMP but you're using a Mac, for example.

 

The defaults for MAMP:

username: "root"

password: "root"

 

The defaults for WAMP:

username: "root"

password: "" (blank - no password)

 

 

falkencreative,

 

Thanks for the reply.

 

I think that it connecting OK. If I comment out the MYSQL stuff, the page runs just fine.

I commented out one line at a time and it's the $result = mysql_query($query); that's throwing the error.

 

Here's the code:

 

<?php

 

// connect to a database

 

$my_connection = mysql_connect('localhost', 'root', '');

 

if(!$my_connection){

die("Could not connect: " . mysql_error());

}

 

echo "Connected Successfully to mySQL server" . "

";

 

$my_database = mysql_select_db('killer');

 

if(!$my_database){

die("Could not find database: " . mysql_error());

}

 

mysql_close($my_connection);

 

 

// set up for accessing the database 'select'

 

//$query = "SELECT * FROM people";

//$result = mysql_query($query);

//$my_rows;

//

//while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

// $my_rows = $my_rows . "Name : {$row['name']}
" . "id : {$row['id']}

";

//}

 

?>

Link to comment
Share on other sites

Are you closing the connection too early? Just a quick guess, and I'm assuming that the code you provide above is exactly the code you are using...

 

I would think you need to do the "my_sql_close" line after you finish using the database. That needs to appear after your code block (which is currently commented out) where you get information from the db.

Link to comment
Share on other sites

Are you closing the connection too early? Just a quick guess, and I'm assuming that the code you provide above is exactly the code you are using...

 

I would think you need to do the "my_sql_close" line after you finish using the database. That needs to appear after your code block (which is currently commented out) where you get information from the db.

 

 

Yep, that was it.

 

Ooops :P

 

You think that I would have caught that one.

 

There is where an extra set of eyes helped.

Many thanks for that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...