PHP Conference Japan 2024

DBA 函式

目錄

新增筆記

使用者貢獻的筆記 4 則筆記

Franz Korntner
12 年前
如果您需要一個「下載資料」按鈕,可以自動開啟試算表程式(例如 Excel),但發現 fputcsv() 無法正常運作,而且所有已安裝的 DBA 資料庫引擎都無法建立可開啟的試算表,而 XLS 產生元件又太過於龐大,那麼這個方法可能正是您需要的。

<?php
// simple table to present
$data = array(
array(
'col1','col2'),
array(
1,2),
array(
3,4)
);

// pretend content (which is XML) is XLS native
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"sheet.xls\";" );

// construct skeleton
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = $dom->preserveSpaces = true; // optional
$n = new DOMProcessingInstruction('mso-application', 'progid="Excel.Sheet"');
$dom->appendChild($n);

$workbook = $dom->appendChild(new DOMElement('Workbook'));
$workbook->setAttribute('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
$workbook->setAttribute('xmlns:o','urn:schemas-microsoft-com:office:office');
$workbook->setAttribute('xmlns:x','urn:schemas-microsoft-com:office:excel');
$workbook->setAttribute('xmlns:ss','xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet');
$workbook->setAttribute('xmlns:html','http://www.w3.org/TR/REC-html40');

$styles = $workbook->appendChild(new DOMElement('Styles'));
$style = $styles->appendChild(new DOMElement('Style'));
$style->setAttribute('ss:ID','Default');
$worksheet = $workbook->appendChild(new DOMElement('Worksheet'));
$worksheet->setAttribute('ss:Name','sheet1');
$xmltable = $worksheet->appendChild(new DOMElement('Table'));

// populate with data
foreach ($data as $datarow) {
$xmlrow = $xmltable->appendChild(new DOMElement('Row'));
foreach (
$datarow as $datacell) {
$xmlcell = $xmlrow->appendChild(new DOMElement('Cell'));
$xmldata = $xmlcell->appendChild(new DOMElement('Data', $datacell));
$xmldata->setAttribute('ss:Type', is_numeric($datacell) ? 'Number' : 'String');
}
}

// display and quit
echo $dom->saveXML();
?>
kevinphpdotnet at stormtide dot ca
20 年前
在 Red Hat 7.3 上使用 db4 時,Apache 子程序可能會收到訊號 11。安裝測試指令碼會回報 db4 運作正常,因為命令列介面不會發出訊號 11。解決方案是檢查 Apache 是否安裝了 mod_rewrite,如果已安裝,請從 libdb.so.3 中取消它的參考,或是在建置 Apache 時不要包含 mod_rewrite。完成後,子程序就不會再異常終止,db4 也能正常運作。如果您在 dba_open 之後沒有收到訊號 11,請忽略此註解。
djm at web dot us dot uu dot net
25 年前
使用 db2 時,您需要呼叫 dba_sync() 將資料寫入磁碟;範例中缺少了這一步。db2 使用
BTREE 檔案格式,而不是更常見的 HASH 格式。
不過,根據我的測試,BTREE 速度更快,所以它是個不錯的
選擇。
To Top