note 94154 deleted from function.die by danbrown
| From: | danbrown@php.net | Date: | Tue, 20 Oct 2009 14:52:19 +0000 |
| Subject: | note 94154 deleted from function.die by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161906@lists.php.net to get a copy of this message | ||
Note Submitter: leo dot renard at softnyx-canada dot net
----
Just a nice tidbit for watch dot do dot sun at gmail dot com's post, this might be a better way
for you to "die" on an unsuccessful MySQL connection, appending "mysql_error()"
within a "die":
<?php
$mysql = array("user" => "root", "password" => "",
"host" => "localhost", "db" => "database");
$connect = mysql_connect($mysql["host"], $mysql["user"],
$mysql["password"]);
if(!$connect){
die("Failed to connect to MySQL due to the following error:" . mysql_error());
}
if(!mysql_select_db($mysql["db"])){
die("Could not select database, " . mysql_error());
}
?>
You can still show the error, and kill the script simultaneously to prevent a function down the line
in the script from doing something disastrous because MySQL couldn't connect.