...

View Full Version : Excel output of Oracle data



florida
06-12-2007, 01:07 AM
I need PHP to show me an Excel output of my Oracle 9i database.

The below would work for MySQL database but how would I do it for Oracle??




<?php
define(db_host, "localhost");
define(db_user, "excel");
define(db_pass, "spreadsheet");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "export2excel");
mysql_select_db(db_name);

$select = "SELECT * FROM TABLE_NAME";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>

marek_mar
06-12-2007, 01:19 AM
Use the oci (http://www.php.net/oci8) functions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum