PHP将数据库内容转化为csv文件,以逗号隔开,为防止数据库内容中含有逗号,影响文件内容显示,需注意添加““(双引号)!!!
<?php include “init.php”; $file_name_=’file.csv’; $str_content_=”aid,username,password,role,status,created_time,updated_time\n”; file_put_contents($file_name_,$str_content_); $query = “select * from administrator”; $list = MysqliClient::ExecuteQuery(‘intern’, $query); foreach($list as $row){ foreach($row as $col){ $str_content_=$col.”,”; file_put_contents($file_name_,$str_content_,FILE_APPEND); } file_put_contents($file_name_,”\n”,FILE_APPEND); }
原文:http://www.phpthinking.com/archives/240
原文地址:http://blog.csdn.net/nextbest/article/details/38990443