Chaos Project

General => Electronic and Computer Section => Programming / Scripting / Web => Topic started by: G_G on March 11, 2011, 07:26:26 pm

Title: MySql PHP No Database Selected
Post by: G_G on March 11, 2011, 07:26:26 pm
I dunno why but I'm getting the mysql_error "No Database selected." However here is my code.
$host = "localhost";
$user = "---";
$pass = "---";
$db = "---";
$connection = mysql_connect($host, $user, $pass);
$database = mysql_select_db($db);
$query = "SELECT * FROM users;";
$result = mysql_query($query);


For obvious reasons, I blocked out the user, pass, and database. Now obviously I'm connecting. I'm not getting any errors from connecting, or from the database selection. Any ideas?
Title: Re: MySql PHP No Database Selected
Post by: Blizzard on March 11, 2011, 07:39:30 pm
Instead of mysql_select_db, try just running the query "USE your_database_name_here;".
Also, have you made sure that this user has access to that database?
Title: Re: MySql PHP No Database Selected
Post by: G_G on March 11, 2011, 07:52:25 pm
*facepalm* I didn't give database access to the user. Fail. Thanks Blizz!