|
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
==================
Navigation:
[Reply to this message]
|