note 94154 added to function.die

From: Date: Tue, 20 Oct 2009 03:06:01 +0000
Subject: note 94154 added to function.die
Groups: php.notes 
Request: Send a blank email to php-notes+get-161891@lists.php.net to get a copy of this message
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. ---- Server IP: 66.207.199.35 Probable Submitter: 68.145.35.99 ---- Manual Page -- http://www.php.net/manual/en/function.die.php Edit -- https://master.php.net/note/edit/94154 Del: integrated -- https://master.php.net/note/delete/94154/integrated Del: useless -- https://master.php.net/note/delete/94154/useless Del: bad code -- https://master.php.net/note/delete/94154/bad+code Del: spam -- https://master.php.net/note/delete/94154/spam Del: non-english -- https://master.php.net/note/delete/94154/non-english Del: in docs -- https://master.php.net/note/delete/94154/in+docs Del: other reasons-- https://master.php.net/note/delete/94154 Reject -- https://master.php.net/note/reject/94154 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161891) next »