Home > Database > Mysql Tutorial > PHP将数据库内容转化为csv文件

PHP将数据库内容转化为csv文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:01:40
Original
1343 people have browsed it

PHP将数据库内容转化为csv文件,以逗号隔开,为防止数据库内容中含有逗号,影响文件内容显示,需注意添加(双引号)!!! ?phpinclude init.php;$file_name_=file.csv;$str_content_=aid,username,password,role,status,created_time,updated_time\n;file_p

PHP将数据库内容转化为csv文件,以逗号隔开,为防止数据库内容中含有逗号,影响文件内容显示,需注意添加““(双引号)!!!

<?php
include &ldquo;init.php&rdquo;;
$file_name_=&rsquo;file.csv&rsquo;;

$str_content_=&rdquo;aid,username,password,role,status,created_time,updated_time\n&rdquo;;
file_put_contents($file_name_,$str_content_);

$query = &ldquo;select * from administrator&rdquo;;
$list = MysqliClient::ExecuteQuery(&lsquo;intern&rsquo;, $query);

foreach($list as $row){
foreach($row as $col){
$str_content_=$col.&rdquo;,&rdquo;;
file_put_contents($file_name_,$str_content_,FILE_APPEND);
}
file_put_contents($file_name_,&rdquo;\n&rdquo;,FILE_APPEND);
}
Copy after login

原文:http://www.phpthinking.com/archives/240

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template