Re: try/catch type constructs?
| From: | CC Zona | Date: | Fri, 01 Feb 2002 21:02:38 +0000 |
| Subject: | Re: try/catch type constructs? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83187@lists.php.net to get a copy of this message | ||
In article <4.3.2.7.2.20020201092919.00c92958@10.10.10.1>,
jsd@cluttered.com (Jon Drukman) wrote:
> the idea being that if any of the commands in the block fail, the database
> package automatically does a die("") and the block is terminated.
>
> the nearest i could get with php is:
>
> do {
> mysql_query("UPDATE ...");
> if (mysql_error()) { $error.="Couldn't update: ". mysql_error(); break; }
>
> mysql_query("SELECT ...");
> if (mysql_error()) { $error.="Couldn't select: ". mysql_error(); break; }
>
> and so on....
> } while (0==1);
>
> if ($error) { do error stuff }
> else { it worked }
Have you read <http://www.php.net/manual/en/features.error-handling.php>
yet? There are some ideas there which you might find useful.
FWIW, there is a die() function in PHP, so you can simplify the above to:
mysql_query("UPDATE ...") or die("Couldn't update: ". mysql_error());
mysql_query("SELECT ...") or die("Couldn't update: ". mysql_error());
--
CC