我如何使用 mysql_fetch_array / mysql_fetch_row 结果创建一个 csv 文件,其中每行记录为 csv,下一条记录在新行中。
我试过这个:
$query = "SELECT * FROM myTable DESC LIMIT 10";
$result = mysql_query($query, $conn);
$resultRows = mysql_num_rows($result);
if($resultRows < 1) {
return array('query' => $query, 'NumberOfRows' => $resultRows, 'status' => 'failure');
};
$rowResult = mysql_fetch_array($result);
//var_dump($rowResult);exit;
foreach($rowResult as $row){
$resultSet = $row['firstname'];
$resultSet .= ',' . $row['lastname'];
$resultSet .= ',' . $row['email'];
$resultSet .= ',' . $row['phone'];
$resultSet .= ',' . ($row['address1']);
$resultSet .= '\n';
//var_dump($resultSet);exit;
}