Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: four minus three?
(Example: nine)

The Note You're Voting On

Anonymous
19 years ago
The following seems counterintuitive to me and so I am constantly getting burned by it. Just thought I'd add a note for anyone else who might also get burned.

if (!odbc_exec("select MyValue from MyTable where Key1='x' and Key2='y'"))

is not a good way to search for the existence of a record with Key1 = x and Key2 = y. The odbc_exec always returns a result handle, even though there aren't any records.

Rather, you must use one of the fetch functions to find out that the record really doesn't exist. This should work:

if (!($Selhand = odbc_exec("select MyValue from MyTable where Key1='x' and Key2='y'"))
|| !odbc_result($Selhand, 1))

<< Back to user notes page

To Top