Page 1 of 1

Need special SQL Error Checking!

Posted: Sun Feb 22, 2004 3:06 pm
by odo324
:?: Can I return a sql error only when the sql statement doesn't run, but not when zero result are returned?

---

Sometimes my statement WILL return no results, and thats OK, but, the code for checking errors...
if (!$result = $db->sql_query($sql))
...will also return an error if no results are found (even if the sql statement ran fine). Which is really bad for me!

Any solutions?

Re: Need special SQL Error Checking!

Posted: Sun Feb 22, 2004 3:22 pm
by morpheus2matrix
odo324 wrote: :?: Can I return a sql error only when the sql statement doesn't run, but not when zero result are returned?

---

Sometimes my statement WILL return no results, and thats OK, but, the code for checking errors...
if (!$result = $db->sql_query($sql))
...will also return an error if no results are found (even if the sql statement ran fine). Which is really bad for me!

Any solutions?


Humm... IIRC,

Code: Select all

if (!$result = $db->sql_query($sql))
will return only if there are errors.
You need to check yourself if there are 0 results, by something like this

Code: Select all

if ( $db->sql_numrows($result) == 0 )
{
      // There are no results
}

Posted: Mon Feb 23, 2004 3:32 am
by odo324
Nope, but I think I figured something out.

This is what I was looking for...

Code: Select all

if ( !isset($result = $db->sql_query($sql)) )
{... ...}
Don't know why I didn't think of using 'isset'! But now that I figured it out, I don't really care. :wink:

Thanks 8)