Reputation: 543
For some reason I am getting the error
No database selected
I have no idea why this is not working, am I being blind?
$con = mysql_connect('localhost','myusername','mypassword');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydatabase');
There are no typos in the actual username, password or database name and I can't see a mistake in my code.
Suggestions are very much appreciated. Thanks
Upvotes: 0
Views: 126
Reputation: 77876
Do you have username
added to the user
table? What if you try the same code with root
user?
Upvotes: 3
Reputation: 4849
try:
mysql_select_db('mydatabase', $con);
in stead of:
mysql_select_db('mydatabase');
Upvotes: 1