Jump to content

Archived

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

mstap42

SOLUTION: sending Oracle NULL to Excel

Recommended Posts

In case anyone wondered...

Recall the problem: I modified the code from the PHPFreaks tutorial "Exporting MySQL To Excel" to send my Oracle data to Excel, but was unable to substitute "\t" for null values, thus:

[!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]while($row = oci_fetch_row($stmt)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t"; // if $value is blank, write a tab...
} else {
...
}[!--fontc--][/span][!--/fontc--]

Tests with ($value == ""), is_null(), and empty() returned *nothing*. Not TRUE, not FALSE, but exactly nothing. So tabs weren't substituted for NULL values, and therefore data got slammed to the left in the Excel file.

Evidently, (and assuming the tutorial's code works as advertised for NULL values), there's not a one-to-one correspondence between mysql_fetch_row and oci_fetch_row.

But, *this* works against Oracle 9i:

[!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]while($row = oci_fetch_array($stmt, OCI_NUM + OCI_RETURN_NULLS)) {
...
}[!--fontc--][/span][!--/fontc--]

If you think you want to try the tutorial's approach, remember that oci_num_fields follows oci_execute. Sounds pretty basic, but it tripped me up the first time.

Thanks to everyone who took a look at the original post!







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.