php+mysql批量导入数据的问题。所有数据都在数据中,遍历数组插入数据,但是只能插入第一条,代码如下
<?php$con=mysql_connect("localhost","root","");mysql_select_db("statistic",$con);mysq...
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("statistic", $con);
mysql_query("set names 'gbk'");
$file_address = "E:\www\person.csv";
$text = trim( file_get_contents($file_address) );
$line_arr = explode( "\n", $text );
foreach($line_arr as $line){
$line_split = explode( ",", $line );
mysql_query("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
?>
请问问题出在哪里,是不是思路错了,麻烦了 展开
$con = mysql_connect("localhost","root","");
mysql_select_db("statistic", $con);
mysql_query("set names 'gbk'");
$file_address = "E:\www\person.csv";
$text = trim( file_get_contents($file_address) );
$line_arr = explode( "\n", $text );
foreach($line_arr as $line){
$line_split = explode( ",", $line );
mysql_query("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
?>
请问问题出在哪里,是不是思路错了,麻烦了 展开
展开全部
首先你把
foreach($line_arr as $line){
$line_split = explode( ",", $line );
mysql_query("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
换成
foreach($line_arr as $line){
$line_split = explode( ",", $line );
echo("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
显示出来看看再说。如果sql没问题就是人品问题了。估计是你的字段问题。比如非空的你有空了。数字类型的你给了字符之类的。
foreach($line_arr as $line){
$line_split = explode( ",", $line );
mysql_query("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
换成
foreach($line_arr as $line){
$line_split = explode( ",", $line );
echo("INSERT INTO basic_individual_customer (customer_id, name, join_time, sex, birth, home_address, home_tel, cellphone) VALUES ('{$line_split[0]}', '{$line_split[1]}', '{$line_split[2]}', '{$line_split[3]}', '{$line_split[6]}', '{$line_split[8]}', '{$line_split[10]}', '{$line_split[11]}')");
}
显示出来看看再说。如果sql没问题就是人品问题了。估计是你的字段问题。比如非空的你有空了。数字类型的你给了字符之类的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
2
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询