我想从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);
}