Need special SQL Error Checking!

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
odo324
Registered User
Posts: 39
Joined: Tue May 13, 2003 6:38 am

Need special SQL Error Checking!

Post 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?
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Re: Need special SQL Error Checking!

Post 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
}
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
odo324
Registered User
Posts: 39
Joined: Tue May 13, 2003 6:38 am

Post 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)
Post Reply

Return to “[2.0.x] MOD Writers Discussion”