alexmahone Posted November 28, 2013 Share Posted November 28, 2013 The below code is not stamping the table rows to CSV, I get empty CSV download file.. pls help <?php $conn = oci_connect('uid', 'pass', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SID=database)))'); if (!$conn) { $e = oci_error(); echo("<br/>".$e); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT server,ipaddress FROM table where rownum<=50 order by kill_time desc '); if (!$stid) { $e = oci_error($conn); echo($e); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Perform the logic of the query $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Fetch the results of the query $ncols = oci_num_fields($stid); echo "<tr>\n"; for ($i = 1; $i <= $ncols; ++$i) { $colname = oci_field_name($stid, $i); } // Query Database $filename = 'file.csv'; $out = ''; // fiels to export $out .='server, ipadress'; $out .="\n"; // Add all values in the table while ($l = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { for ($i = 0; $i < 2; $i++) { $out .=''.$l["$i"].','; } $out .="\n"; } // Output to browser with appropriate mime type header("Content-type: text/x-csv"); header("Content-Disposition: attachment; filename=$filename"); echo $out; exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/284352-downloadable-csv-from-oracle-db-tables/ Share on other sites More sharing options...
Barand Posted November 28, 2013 Share Posted November 28, 2013 if you comment out the header function calls, does it produce the correct data output? Quote Link to comment https://forums.phpfreaks.com/topic/284352-downloadable-csv-from-oracle-db-tables/#findComment-1460506 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.