I am trying to import a CSV from a database. My query was working great with my localhost. Now I'm using Amazon RDS Server and it's not working; is there any way to grant file permission in Amazon RDS user privilege?
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?
I have found the only solution to do this using php is like this:
$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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.