glln
glln

Reputation: 543

No Database Selected Error - Don't know why

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

Answers (2)

Rahul
Rahul

Reputation: 77876

Do you have username added to the user table? What if you try the same code with root user?

Upvotes: 3

Bono
Bono

Reputation: 4849

try:

mysql_select_db('mydatabase', $con);

in stead of:

mysql_select_db('mydatabase');

Upvotes: 1

Related Questions