将数据库的用户导出到CSV文件中。
1,cc.html文件
2,php导出csv文件 quku.php
<?php
$ip = $_POST["ipaddr"];
$user = $_POST["dbuser"];
$db = $_POST["dbname"];
$pass = $_POST["passwd"];
@$con = mysql_connect("$ip","$user","$pass");
if (!$con) {
die (”数据库连接失败:“ . mysql_error());
exit;
}
$data = mysql_select_db("$db",$con);
if (!$data) {
echo mysql_error();
mysql_close($con);
exit;
}
else {
//输出Excel文件头
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="shuju.csv"');
header('Cache-Control: max-age=0');
$sl = "SELECT User,Password FROM user WHERE user='root'";
$result = mysql_query($sl,$con);
$fp = fopen("php://output","a");
$head = array("用户","密码");
foreach ($head as $i => $v){
$head[$i] = iconv('utf-8','gbk',$v);
}
//fputcsv(file,fields) 将一行(用 fields 数组传递)格式化为 CSV 格式并写入由 file 指定的文件
fputcsv($fp,$head);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
fputcsv($fp,$row);
}
mysql_close($con);
}
?>