Jump to content


SOLUTION: sending Oracle NULL to Excel

  • Please log in to reply
No replies to this topic

#1 mstap42

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 31 January 2006 - 05:14 PM

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 {

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)) {

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!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users