PHP & Mysql mysql_select_db()

OKay What an I missing or doing wrong?
whfwo0rks_steve has full permissions on the db

  1. The Connect seems te work OK

$link = mysql_connect( $localhost, $username, $password ) or die('Could not connect: ’ . mysql_error());
echo ‘Connected successfully to:’;
echo “
mysql error[”.mysql_error()."]
";
echo $database."
";
echo $link."
";

  1. The Select DB fails.

$db_selected = mysql_select_db($database, $link);
echo “db_selected[”.$db_selected."]
";
if (!$db_selected) {
die ('Can’t use DB: ‘.$database.’
Mysql_error: '.mysql_error());
}

This is the output from my php prog.

wfhworks_steve
_wfhworks1
localhost
Connected successfully to:
mysql error[]
_wfhworks1
Resource id #2
db_selected[]
Can’t use DB: _wfhworks1
Mysql_error: Access denied for user ‘wfhworks_steve’@‘localhost’ to database ‘_wfhworks1’

mysql_select_db uses the mysql_connect to you don’t have a var for it instead use the $link

here’s how I do it:

[php]
$conn = mysql_connect (DBHOST, DBUSER, DBPASS);
$conn = mysql_select_db (DBNAME);
if(!$conn){
die( “Sorry! There seems to be a problem connecting to our database.”);
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service