$hostname='example.com';
$username='someUser';
$password='password';
$dbname='aDataBase';
$usertable='my_table';
mysql_connect($hostname,$username,$password);
@mysql_select_db($dbname) or die( "Unable to select database");
I'm using a read-only username here. When i test the script, i get the error "unable to select database"开发者_运维技巧.
Any clue?
Don't use fixed strings for your die() message...They're useless for diagnosis. As well, don't supress errors with @
.
mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
Using this you'll get the exact reason things are failing.
Try this
$db_name = "DATABASE";
$db_user = "USER";
$db_pass = "1234";
$db_serv = "localhost";
$res = @mysql_connect($db_serv,$db_user ,$db_pass);
if($res)
mysql_select_db($db_name) or die(mysql_error());
精彩评论