這就像繼續從PHP使用PHP獲取數據並同時流出到http。如何從數據庫讀取並寫入http流。 php和mysql
像在java中我們可以寫入ServletOutput流?
數據的大小可以像200 MB。
感謝
這就像繼續從PHP使用PHP獲取數據並同時流出到http。如何從數據庫讀取並寫入http流。 php和mysql
像在java中我們可以寫入ServletOutput流?
數據的大小可以像200 MB。
感謝
我認爲你正在尋找刷新輸出緩衝區在PHP中。欲瞭解更多信息,請參閱PHP手冊中的flush函數和其他輸出控制函數。
下面是一個腳本,它在一個表上執行幾個select語句,並將每個結果行寫入輸出流。它確實沒有不同於回顯,但也許你可以適應它,例如,通過使用不同的流包裝(預定義或自定義)。當然,請添加安全和錯誤檢查代碼。
假設一個包含「name」和「home_country」字段的表。
$dsn = 'mysql:host=localhost;dbname=test';
$uname = 'uname';
$pword = 'password';
$countries = array('Mexico', 'Egypt', 'Estonia', 'Australia');
$pdo = new PDO($dsn, $uname, $pword);
$qry_stmnt = 'SELECT name, home_country
FROM places_test
WHERE home_country = :country';
$stmnt = $pdo->prepare($qry_stmnt);
$out_stream = fopen('php://output', 'w');
foreach ($countries as $country) {
$result = $stmnt->execute(array(':country' => $country));
$obj = $stmnt->fetchAll(PDO::FETCH_OBJ);
foreach ($obj as $row) {
fwrite($out_stream, $row->name . ': ' . $row->home_country . '<br />');
}
}
fclose($out_stream);
我認爲其「沖洗」我想要的,但肯定需要看看文檔。謝謝:) – Vishal 2009-11-12 17:44:43