我的應用程序是在服務器A和數據庫中的其他服務器服務器B. 與MySQL OUTFILE成/服務器B. 的tmp目錄下我想用PHP代碼下載服務器APHP下載文件
這個文件<?php
$fullpath = '/tmp/users.csv';
Mysql SELECT ......INTO OUTFILE '$fullpath'
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
ESCAPED BY '\"'
LINES TERMINATED BY '\n'
$connection = ssh2_connect('serverb', 22);
ssh2_auth_password($connection, 'username', 'password');
if(ssh2_scp_recv($connection, $fullpath, $fullpath)) {
echo $filepath.' copied to server!!';
}
$filename1 = 'users.csv';
$mm_type="application/csv";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-Type: application/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$filename1.'"');
header("Content-Transfer-Encoding: binary\n");
readfile($fullpath);
exit;
?>
與MySQL選擇保存在服務器B OUTFILE文件,但無法從服務器A,其中的PHP代碼運行 問候
嘿,語法錯誤!你不能像這樣執行的查詢? – Raptor 2015-03-13 08:29:25
@Raptor;查詢正確執行,我得到ServerB上「/tmp/users.csv」 csv文件。這裏是一個查詢的例子SELECT'First Name','Last Name','User Code' UNION (SELECT fname,lname,ucode FROM csvfields INTO OUTFILE'$ fullpath' FIELDS TERMINATED BY',' ENCLOSED BY' \「」 ESCAPED BY '\」' LINES TERMINATED BY '\ n' ) – Aruti 2015-03-15 09:49:36