2010-10-26 97 views
0

我写了一个PHP脚本到一个文本文件中的内容插入到MySQL数据库和我的文件的A.TXT内容PHP脚本文件的内容加载到MySQL数据库

\ n用于新行

我希望它被加载到数据库中包含特殊字符 \ n

因为它是... 但正在加载仅“用于新行” 好心帮我... 感谢名单

<?php 
$filename = "a.txt"; 
$f = fopen($filename, 'r'); 
$total_contents = fread($f, filesize($filename)); 
print $total_contents; 
mysql_connect("localhost", "datab_user", "password") or die(mysql_error()); 
mysql_select_db("datab_name") or die(mysql_error()); 
mysql_query("INSERT INTO table_name 
(id,content) VALUES(333,'$total_contents') ") 
or die(mysql_error()); 
?> 
+0

你不能使用load data infile - http://dev.mysql.com/doc/refman/5.1/en/load-data.html ??比较... – 2010-10-26 07:15:37

回答

0

你要逃避它。如果你想在MySQL中的换行,送\ n到服务器,如果你想有一个\ n,发送\\ñ

0

如果你想成\ n出现在DB里面的是(即如\其次ñ而不是作为一个新行),那么你必须要逃避它,所以你必须发送\\ n被用于新的生产线到数据库。

顺便说一句如果您只是想将完整的文件内容读入字符串中,您还可以使用file_get_contents

0

请尝试查看mysql_real_escape_string的PHP手册以将输入转义为mysql数据库。

+0

...工作... – user868769 2010-10-28 06:03:02

相关问题