Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

mstap42

Oracle NULL and PHP

Recommended Posts

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, profile
FROM mydb.operators

If middle_initial contains nothing, the profile value is written in the middle_initial column:
last_name first_name middle_initial profile
Simpson Homer admin

I 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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.