PHP 8.5.0 RC 2 available for testing

Voting

: seven plus one?
(Example: nine)

The Note You're Voting On

Anonymous
20 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

AltStyle によって変換されたページ (->オリジナル) /