I am using the following code to connect to a local database:
$db_name = "MyDB";
$conn = mysql_connect("localhost", "MyName", "MyPassword") or die ("Couldn't connect.");
$db = mysql_select_db($db_name, $conn) or die ("Couldn't select local database -- $db_name");
Everything works fine, as expected, until I try to switch the database. Then it always fails at the select_db statement.
For example, if I try to use another database as:
$db_name = "AnotherDB";
this dies with the error "Cannot select local database . . . "
IOW, it connects, but won't select!
I can see this other database from the MySQL monitor, even list its tables, so I know there is nothing wrong with it.
Very weird, and has had me puzzled for weeks. Basically, MySQL is telling me that I can only have one database it will connect to!
Even switching DB's at the monitor with the "use DB" command does not help (altho the monitor works just fine, but not this script).
Any suggestions would be appreciated.