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

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

PHP中文网
PHP中文网Original
2016-05-25 17:11:011831browse
跳至     
<?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
?>



Statement:
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