I am trying for a workable program in which data should be fetched based on input ids and should be save as csv file format. Based on other's question, I wrote program but why it does not fetch the data?
<?php
header("Content-type: text/csv");
header("Content-Disposition: attachment;filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
$dbc = "mysql:host=localhost;dbname=experiment";
$user = "katiee";
$pass = "******";
$dbo = new PDO($dbc, $user, $pass);
$sql = "SELECT * FROM clone WHERE id='001'";
$qry = $dbo->prepare($sql);
$qry->execute();
var_dump($qry->fetch(PDO::FETCH_ASSOC));
$data = fopen('file.csv', 'w');
while ($row = $qry->fetch(PDO::FETCH_ASSOC))
{
fputcsv($data, $row);
}
?>
I think there is no record asociated with id='001'
. Try with "1".
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.