2010-10-26 63 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

相關問題