Hello...
mysql_select_db('phpcake') or die('Cannot select database');
"or die" is really necessary or is just for precaution?
Thank you!
Die
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Die
It's a precaution, but it should be used or it will lead to problems in your script if you try to use the MySQL connection for anything after selecting the database failed.
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Re: Die
I've always considered die() to be a rather ugly way to handle errors, because it does nothing other than terminate the script with a message.
It's okay for debugging, but for the release script I prefer a somewhat more sophisticated way of continuing the script on an alternate path.
That's a bit oversimplified, as the db selection can also fail, but you can get the idea.
It's okay for debugging, but for the release script I prefer a somewhat more sophisticated way of continuing the script on an alternate path.
Code: Select all
$Host = "xxx.xxx.xxx";
$User = "me";
$Password = "password";
$Link = @mysql_pconnect($Host, $User, $Password);
if ($Link)
{ $dbmName = "whatever";
mysql_select_db($dbmName, $Link);
// etcetera
}
else
{
echo "Failed to connect to database";
// and take other measures as needed
}