1, we generally do the idea of exporting is, according to the data we want, all the query out, and then export, this is a large amount of data will be very slow, here I put forward the idea is paging and buffering to achieve dynamic output .
2. Ordinary I will not say, below I say the paging and memory refresh ideas. The code is as follows:
$conn = Oci_connect (' Fin_data ', ' Fin_data ', "(Description= (address= (PROTOCOL =tcp) (host=192.168.6.65) (PORT = 1521)) ( Connect_data = (SID=HQYGDW)));
$sqlName = "SELECT *
From User_tab_columns
where Table_name= ' S_sale_receivable_detail '
ORDER BY column_name ";
$filedName = Oci_parse ($conn, $sqlName);
Oci_execute ($filedName, Oci_default); Number of rows Oci_default means no automatic commit
Header (' CONTENT-TYPE:APPLICATION/VND.MS-EXCEL;CHARSET=GBK ');
Header (' Content-disposition:attachment;filename=test_ '. Time (). '. csv ');
Header (' cache-control:max-age=0 ');
$fp = fopen (' php://output ', ' a ');
$head = Array ();
$i = 0;
while ($row = Oci_fetch_array ($filedName, OCI_ASSOC + oci_return_nulls)) {
$head [$i] = iconv (' utf-8 ', ' GBK ', $row [' column_name ']);
$i + +;
}
Fputcsv ($fp, $head);
$selectCount = "SELECT count (*) as counts from S_sale_receivable_detail T";
$resultCount = Oci_parse ($conn, $selectCount); Configuring SQL statements, executing SQL
Oci_execute ($resultCount, Oci_default); Number of rows Oci_default means no automatic commit
$count = Oci_fetch_array ($resultCount, Oci_assoc + oci_return_nulls);
$count [' COUNTS ']=10;
$pageNum = 50000;
$pagePre = Ceil ($count [' COUNTS ']/$pageNum);
for ($i = 1; $i <= $pagePre; $i + +) {
$pageStart = ($i-1) * $pageNum + $pageNum;
$pageEnd = ($i-1) * $PAGENUM;
$select = "SELECT *
From (SELECT a.*, ROWNUM RN
From (SELECT * from S_sale_receivable_detail) A
WHERE ROWNUM <={$pageStart})
WHERE RN >= {$pageEnd} ";
$result = Oci_parse ($conn, $select); Configuring SQL statements, executing SQL
Oci_execute ($result, Oci_default); Number of rows Oci_default means no automatic commit
$count = 0;
while ($rowResult = Oci_fetch_array ($result, OCI_ASSOC + oci_return_nulls)) {
Print_r (Explode (', ', $rowResult)); exit;
Fputcsv ($fp, $rowResult);
$count + +;
if ($count >= $pageNum) {
Ob_flush ();
flush ();
}
}
}
Fputcsv ($fp, $head);
PHP Connection Oracle Export millions data