实例一breakfast是什么意思:
<?php
$filename = ‘test’;
//导出文件
header(“content-type: application/vnd.ms-excel; chart=utf-8”);
header(“content-disposition: attachment; filename=”.$filename.”.csv”);
echo “商品名称,商品编号,商品价格,商品品牌,商品颜色\n”;
$arr = [
[‘貂秋1′,’dq00001′,’1000′,’雕牌’,’红色’],
[‘貂秋2′,’dq00002′,’1000′,’雕牌’,’蓝色’],
[‘貂秋3′,’dq00003′,’1000′,’雕牌’,’绿色’],
[‘貂秋4′,’dq00004′,’1000′,’雕牌’,’白色’]
];
//将数组循环遍历并输出
foreach ($arr as $item){
echo implode(‘,’,$item).”\n”;
}
示例二:
//从数据库中导出
$conn = mysqli_connect(‘localhost’,’root’,’123456′,’st0614′);//连接数据库
$filename = ‘student’;//文件名为student
header(“content-type: application/vnd.ms-excel; chart=utf-8”);
header(“content-disposition: 大学生自我总结范文attachment; filename=”.$filename.”.csv”);
$res = mysqli_query($conn,’lect * from student’);
echo “id,姓名,性别,年龄,院系,班级,头像\n”;//表头
while($row = mysqli_fetch_assoc($res))//获取数据库数据
{
$arr[] = $row;
}
foreach ($arr as $item){
echo implode(‘,’,$item).”\n”;//输出
}
//svn导入数据库
$file = ‘text.txt’;
if (ist($_post[‘commit’])){
$file = $_files[‘csv’];
$filename=$file[‘tmp_name’];
$fp = fopen($filename,’r’);
$i=0;
while ($file_data = fgetcsv($fp))
{
$i++;
if($i==1)
{
continue;//过滤表头
}el{
$data[$i] = $file_能力的英文data;
}
}
fclo($fp);
}
<– ———请分开——— –>
//存入数据库
if (ist($data)){
foreach ($data as $item){
$name = iconv(‘gb2312′,’utf-8’,$item[1]);
$sql = “inrt into student(`name`,`x`,`age`,`d_id`,`class_id`,`tumble`) values(‘{$name}’,{$item[2]},{$item[3]},{$item[4]},{$item[5]},'{$item[6]}’)”;
$res = mysqli_query($conn,$sql);
}
if ($res){
echo ‘上传成功!’;
}el{
echo ‘上传失败!’;
}
}
?>
<!doctype html>
<html lang=”en”>
<head>
<meta chart=”utf-8″>
<meta name=”viewport”
content=”width=device-width, ur-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0″>
<meta http-equiv=”x-ua-compatible” content=”ie=edge”>
<title>document</title>
</head>
<body>
<form action=”” method=”post” enctype=”multipart/form-data”>
csv文件:
<input type=̶中国管理传播网1;file”name=”csv”>
<–<butt大一新生大学规划on id=”btn” onclick=”<?php //download(); ?>”>下载</button>–>
<input type=”submit” name=”commit” value=”上传”>
</form>
</body>
</html>
本文发布于:2023-04-07 12:13:00,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/eb3f3889232c350dd60f7abddba13572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:CSV文件导入数据库和导出数据库.doc
本文 PDF 下载地址:CSV文件导入数据库和导出数据库.pdf
留言与评论(共有 0 条评论) |