Re: Exceptions in PHP

From: Date: Mon, 15 May 2006 02:15:13 +0000
Subject: Re: Exceptions in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-236165@lists.php.net to get a copy of this message
On Sun, May 14, 2006 2:10 pm, John Meyer wrote: > try { > $conn = mysql_connect("localhost","webuser","testme") or > die("Could > not > connect"); Seems to me you ought to use throw() here... > mysql_select_db("bookcollection",$conn) or die("Could not select > database"); Ditto. > //first, check to see if there is an author > if ($_POST["neworoldauthor"] == "new") { > mysql_query($sql); > } catch(Exception $e) { Call me wacky, but to me, the 'catch' is parallel in indentation with the 'try'... :-) > echo $e->GetMessage(); > mysql_query("ROLLBACK"); Hello? Is mysql_connect() doing some magical "BEGIN" for you automatically? It COULD be, but I think even if it is, you should do your own BEGIN to be 100% clear in your PHP source code where the transaction starts. > } > ?> > > I'm trying to get to the point where if the query doesn't execute, it > pops out a message and rollsback any possible results. It doesn't. > What's wrong on this script? Does it print the error? Actually, what makes you think anything in all that is going to throw an exception? I don't think any of PHP extensions throw errors (thank God) yet. The Unicode [bleep] might, depending on how that big flame-war in "Internals" work[s|ed] out... You need to do your own 'throw' if you want your 'catch' to execute, almost for sure. Disclaimer: Ain't never used PHP Exceptions, and don't like 'em, so I don't really know what I'm talking about. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#236165) next »