Reply to Re: mysql, classes, exceptions and error handling

Your name:

Reply:


Posted by Jerry Stuckle on 09/20/05 05:47

Ramza Brown wrote:
>
> This mysql_error doesnt give me an error below, but when I run it at the
> global scope it does give me errors. I went ahead and checked for
> mysql_error(), but normally I dont have to, why?
>
> public function runQuery() {
>
> try {
> /// Use mysql_error() to check for errors
> if (!empty($this->build_query)) {
> $this->sql_result = mysql_query($this->build_query);
>
> $this->lastinsertid = mysql_insert_id();
> $err = trim(mysql_error());
> if (!empty($err)) {
> throw new Exception("".$err);
> } // end of if - check error
>
> } // end of if //
>
> } catch(Exception $e) {
>
> $this->error_message = "ERR: ".$e->getMessage();
>
> if ($this->verbose == 1)
> echo $this->error_message;
>
> } /// end of try - catch //
>
> return $this->error_message;
> } // end of the method //
>
>

Well, let's see here.

First of all - you should check the response of mysql_query() (in
$this->sql_result in your code) to determine if you have an error. And
you need to do that before you call mysql_insert_id().

Only call mysql_insert_id() if it is indeed an insert.

And you should ALWAYS check the response of ANY mysql call to see if it
worked!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация