Re: Exceptions in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux