我想从 SQL 查询结果创建一个 CSV 文件。到目前为止,我一直在使用本地存储来存储文件。但现在我想打开一个 ftp 连接并打开文件并写下我的 chnages。
我的代码如下:
$ftp_server = "subdomain.domain.com";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, 'uN@m3', '$pWd00');
$filename = 'ftp://uN@m3:$pWd00@subdomain.domain.com.com:21/db_user_export_'.time().'.csv'; //Change this to FTP URL of the server where File is going to be placed
function populateCSVforRightNowDatabase(){
global $database, $filename, $queryInterval, $logger;
/*My Query*/
if($resultSet->load()) {
// Create or Overwrite file
$handle = fopen($filename, 'w+');
// Write the spreadsheet column titles / labels
fputcsv($handle, array( /*columns*/));
foreach($resultSet as $result) {
fputcsv($handle, array(/*Results*/));
}
} else {
$message = "Load Error: " . $resultSet->getLoadError();
$logger->error($message);
}
// Finish writing the csv
fclose($handle);
}