PHP CSV导入数据库

WBOY
Release: 2016-06-23 14:37:31
Original
1239 people have browsed it

duDaoRuConfig.php页面

$csv_key_name){ $result_arr[$i][$csv_key_name] = $data_line[$csv_key_num]; } $i++; } return $result_arr;}?>
Copy after login

doDaoRu.php


Copy after login

doDaoRu2.php

列名:


Copy after login

doDaoRu3.php

$table_real_column_name){ if($j == count($table_real_column_name_arr)){ $csv_line_data_value .= " ' ".$result_arr[$i][$csv_real_key_name]."' "; }else{ $csv_line_data_value .= " '".$result_arr[$i][$csv_real_key_name]."', "; } $j++; } $all_insert_data_value_str .= " ($csv_line_data_value) ,";}$all_insert_data_value_str = substr($all_insert_data_value_str,0,-1); //去掉最后一个逗号//拼凑所有需插入值的字段名到一个长字符串的sql语句中$all_insert_column_name_str = "";$i = 1;foreach($table_real_column_name_arr as $csv_real_key_name=>$table_real_column_name){ if($i == count($table_real_column_name_arr)){ $all_insert_column_name_str .= " $table_real_column_name "; }else{ $all_insert_column_name_str .= " $table_real_column_name , "; } $i++;}//问题,1文本中如有回车换行会导致字符串中有转义字符导入失败,2中文乱码//执行批插入,csv导入完成$query = mysql_query("insert into $tableName ($all_insert_column_name_str) values $all_insert_data_value_str");//批量插入数据表中fclose($csv_file);if($query){ echo '导入成功!';}else{ echo '导入失败!';}?>
Copy after login

doDaoRuAjax.php

Copy after login

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 Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!