0

PHPでこれを行う方法は?

テーブルデータのみをcsvファイルにエクスポートし、csvファイルをバックアップフォルダに保存したくありません。

このために私はこれを使用しています:

$query = "SELECT * FROM `login_details`";
$file_name = "login_details";
$sql_csv = mysql_query($query) or die("Error: " . mysql_error()); //Replace this line with what is appropriate for your DB abstraction layer

header("Content-type:text/octect-stream");
$done = header("Content-Disposition:attachment;filename=$fileName");

while($row = mysql_fetch_row($sql_csv)) {
     print '"' . stripslashes(implode('","',$row)) . "\"\n";
}

ありがとう。

4

3 に答える 3

0

http://php.net/manual/en/function.fopen.phpを使用して書き込む (処理する) ファイルを開く必要があります

作成したハンドルを使用して文字列http://php.net/manual/en/function.fputcsv.phpを書き込みます

完了したらハンドルを閉じる (fopen のドキュメントを参照) fclose() を使用

例えば:

//you code to get data from sql
$handle = fopen('full path to store (you can use ftp etd)', 'w'); // see mode
while($row = mysql_fetch_row($sql_csv)) {
     fputcsv($handle, $row);
}
fclose($handle);
于 2013-07-22T08:04:44.767 に答える