简体   繁体   English

用PHP在Excel工作表中导入和导出Oracle数据

[英]Import and Export Oracle Data in Excel Sheet in PHP

PHP,Oracle Error I am Trying to Import and Export Oracle database in Excel Sheet Using PHP But Facing Error and troubleshooted on Google but failed To resolve The code is given below with error PHP,Oracle错误我正在尝试使用PHP在Excel工作表中导入和导出Oracle数据库,但遇到错误并在Google上进行了故障排除,但无法解决该代码在下面给出了错误

ora-24338 statement handle not executed in oracle
'<?php
$conn = oci_connect('akh', 'spic', 'scan/rcf');
  if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$output = "";
$sql  = oci_parse($conn, "select *  from mgr.fa_elec_cash ");
oci_execute($sql, OCI_DESCRIBE_ONLY); // Use OCI_DESCRIBE_ONLY if not fetching rows
$columns_total = oci_num_fields($sql);
for ($i = 1; $i < $columns_total; $i++) {
$heading = oci_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";
while ($row = oci_fetch_assoc($sql)) {
    for ($i = 1; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
 }  
$filename = "myFile.csv";
header('Content-type: application/csv');
header('Content-Disposition:attachment; filename='.$filename);
echo $output;
exit;
?>'

Try this one.. 试试这个

` `

$query = 'select *  from mgr.fa_elec_cash';
$stid = oci_parse($conn, $query);
oci_execute($stid);

$myfile=fopen("myFile","w") or die("Unable to open File");

$columns_total = oci_num_fields($stid);
$output = "";
for ($i = 1; $i <= $columns_total; $i++) {

   $heading = oci_field_name($stid, $i);
   $output .= '"'.$heading.'",';
}
$output .="\n";
while(($row=oci_fetch_array($stid,OCI_BOTH))!=false)
{

  for ($i = 0; $i < $columns_total; $i++) {
    $output .= '"'.$row[$i].'",';

 }
 $output .="\n";
}
oci_free_statement($stid);
oci_close($conn);
fwrite($myfile, $output);
echo "Data successfully exported";
fclose($myfile);

?>` 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM