Home > php教程 > PHP源码 > php逐行读取txt并导入数据库

php逐行读取txt并导入数据库

PHP中文网
Release: 2016-05-25 17:11:01
Original
1861 people have browsed it
跳至     
<?php
//作者:www.tongqiong.com
set_time_limit(13600);  //设置时间
$conn=mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;&#39;); //连接数据库
mysql_select_db(&#39;tongqiong&#39;,$conn);
mysql_query("SET NAMES utf8");

$fp_in = fopen(&#39;F:/sql/www.tongqiong.com.txt&#39;, "r");
while (!feof($fp_in)) {
    $line = fgets($fp_in);
    //$u=explode(&#39;# &#39;, $line);//如果有分割
    mysql_query("INSERT INTO `user` (title)VALUES(&#39;trim($line)&#39;)",$conn); 
}
echo &#39;OK&#39;;
//作者:www.tongqiong.com
?>
Copy after login



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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template