[英]How to use into out file query in Amazon RDS
I am trying to import a CSV from a database. 我正在尝试从数据库导入CSV。 My query was working great with my localhost. 我的查询在本地主机上运行良好。 Now I'm using Amazon RDS Server and it's not working; 现在,我正在使用Amazon RDS Server,它无法正常工作; is there any way to grant file permission in Amazon RDS user privilege? 有什么方法可以授予Amazon RDS用户权限中的文件权限?
My current query is this : 我当前的查询是这样的:
$path = getcwd() . '/uploads/data.csv' ;
$sql = "SELECT 'Name', 'Email', 'Type of inquiry' , 'Message'
UNION ALL
SELECT `engine4_mytable_contacts`.name ,
`engine4_mytable_contacts`.email,
`engine4_mytable_contacts`.topic,
`engine4_mytable_contacts`.feed_back
FROM engine4_mytable_contacts WHERE contact_date >= '$prevDate' into outfile '$path' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n\r'";
$result = $connection->prepare($sql);
$result->execute();
How can I alternatively run this query using PHP? 如何使用PHP运行该查询?
I have found the only solution to do this using php is like this: 我发现使用php的唯一解决方案是这样的:
$sql = "SELECT `engine4_mytbl_contacts`.name ,
`engine4_mytbl_contacts`.email,
`engine4_mytbl_contacts`.topic,
`engine4_mytbl_contacts`.feed_back
FROM engine4_mytbl_contacts WHERE contact_date >= '$prevDate'";
$result = $db->prepare($sql);
$result->execute();
$rows = $result->fetchAll(PDO::FETCH_OBJ);
$file = fopen($path, "w"); // this will open the file and erase all datas
foreach($rows as $val){
$array = array($val->name,$val->email,$val->topic,$val->feed_back);
fputcsv($file,$array);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.