将OICQ数据转成MYSQL数据
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-25
p; $fp = fopen($csv_file, "r"); // show first line of the csv file to select dababase table and its fields echo "<form method=post action=$PHP_SELF>"; $csv_data = fgetcsv($fp, 2000, "$terminated"); $num = count($csv_data); for ( $c=0; $c<$num; $c++ ) { $field_name[$c] = $csv_data[$c]; echo $field_name[$c] . " n"; $table_field_name = "field$c"; show_field($db,$table,$c,$table_field_name); echo "<br>"; } // copy the tmp file for next use $dest = "/tmp/csv_file.csv"; copy($csv_file,$dest); echo "<input type=hidden name=csv_file value=$dest>n" . "<input type=hidden name=table value=$table>n" . "<input type=hidden name=terminated value=$terminated>n" . "<input type=submit name=submit value=ok></form><p>n"; // when click ''ok'' button ,start insert data if ($submit == "ok") { $NO = 1; while ($csv_data = fgetcsv($fp, 2000, "$terminated")) { //$num = count($csv_data); for ( $c=0; $c<$num; $c++ ) { $table_field_name = "field$c"; $first_3 = substr($table_field_name, 0, 3); $first_2 = substr($table_field_name, 0, 2); $val_tmp = ($first_3 == "fid" || $first_3 == "int" || $first_2 == "id") ? $csv_data[$c] : "''" . $csv_data[$c] . "''"; $val .= $val_tmp . ","; $var .= $table_field_name . ","; } $val = substr($val, 0, -1); $var = substr($var, 0, -1); $query = "INSERT INTO $table ($var) VALUES ($val)"; $val = ""; $var = ""; $q->query($query); echo "NO. $NO $query<p>"; $NO++; } fclose($fp); } } } ?> |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 怎样在php中使用PDF文档功能下一篇: 简单的页面缓冲技术
关于将OICQ数据转成MYSQL数据的所有评论