bnther Posted February 22, 2010 Report Share Posted February 22, 2010 I'm going through the PHP-MYSQL tutorials and I've hit this block. I've checked the 'killer' database and it clearly says 'YES' with ALL PRIVILEGES. Where is this ODBC user coming from and most importantly, how to I grant it access? Thanks bnther Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 22, 2010 Report Share Posted February 22, 2010 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) Quote Link to comment Share on other sites More sharing options...
bnther Posted February 22, 2010 Author Report Share Posted February 22, 2010 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']} "; //} ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 22, 2010 Report Share Posted February 22, 2010 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. Quote Link to comment Share on other sites More sharing options...
bnther Posted February 22, 2010 Author Report Share Posted February 22, 2010 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 You think that I would have caught that one. There is where an extra set of eyes helped. Many thanks for that. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 22, 2010 Report Share Posted February 22, 2010 Sure thing. Sometimes if you stare at a a piece of code too long, you start missing things. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.