php读取txt文档内容添加到数据库

来源:百度知道 编辑:UC知道 时间:2024/06/19 07:12:53
文档格式规范<br>识别.
读取到了.txt文档了 怎么实现读取的txt文档数据添加到数据库里面
页面直接报内部服务器错误 我看不出来错在哪..

$content = file_get_contents("filename.txt");
$contents = explode("<br>",$content);

这个$contents就是你要的数组,然后进行数据库插入操作!

$content = file_get_contents($p);
$contents = explode("\r\n",$content);
$ini_array = parse_ini_file("config.ini");
print_r($ini_array);
$con=mysql_connect($ini_array[host],$ini_array[name],$ini_array[pwd]);
if(!$con){
echo "数据库连接失败";
}
$db = mysql_select_db("jingcai", $con);
if(!$db){
echo "数据库选择失败";
}
$sql =mysql_query('set names gb2312');
mysql_query($sql);
$sql="insert into user(tel,money,name) values('"$contents[1]"','"$contents[2]"', '"$contents[3]"')";
if (!mysql_query($sql,$con))
{
die('Error:'.mysql_error());
}
echo "<script>alert('ok');</script>