mstap42 Posted January 27, 2006 Share Posted January 27, 2006 I've run into a bit of a snag with querying Oracle in PHP and wondered if you had any ideas. The problem is null values. With my scripts, when data is sent to HTML tables or Excel, the nulls aren't recognized, and the value to the right is moved into that blank position. Otherwise, where all fields have some content, the data is displayed correctly.Example:SELECT last_name, first_name, middle_initial, profileFROM mydb.operatorsIf middle_initial contains nothing, the profile value is written in the middle_initial column:last_name first_name middle_initial profileSimpson Homer adminI would like to be able to substitute a blank value with something like a tab (\t). But tests with PHP's is_null() and empty() functions seem to show that these functions do not recognize the Oracle null at all. With error_reporting set to 2047 (E_ALL), they return nothing--neither Null nor Not Null, neither Empty nor Not Empty. Whether a field is populated or not, isset() shows the value to be Set.So conditional statements like this fail:[!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]if ((!isset($value)) || ($value == "")) { $value = "\t";}[!--fontc--][/span][!--/fontc--]The conditions [!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]is_null($value)[!--fontc--][/span][!--/fontc--] and [!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]empty($value)[!--fontc--][/span][!--/fontc--] also fail.Is there something about Oracle null values that PHP can't see? Is there some other function I could use to identify Oracle nulls for character substitution?Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/3263-oracle-null-and-php/ Share on other sites More sharing options...
mandrews81 Posted December 7, 2006 Share Posted December 7, 2006 When fetching your row try using [i]while ($row = oci_fetch_array ($statement, OCI_ASSOC+OCI_RETURN_NULLS ))[/i]The OCI_RETURN_NULLS will create empty elements for the NULL fields.See http://us2.php.net/manual/en/function.oci-fetch-array.php for more info. Quote Link to comment https://forums.phpfreaks.com/topic/3263-oracle-null-and-php/#findComment-136626 Share on other sites More sharing options...
rjgoulet Posted February 27, 2007 Share Posted February 27, 2007 You might also try using Oracle's NVL function. Quote Link to comment https://forums.phpfreaks.com/topic/3263-oracle-null-and-php/#findComment-195466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.