2016-04-15 83 views
-1

我有.txt文件中的數據。從txt文件插入數據到數據庫PHP

4654664 
6545645646 
54564121452 
564754412 
5456545 

我想用PHP

<?php 
$host= "localhost"; 
$user= "infdgfg"; 
$pass= "98fgfgdghf6"; 
$db="xxxxx"; 

$connect= mysql_connect($host,$user,$pass); 
if (!$connect)die ("Cannot connect!"); 
mysql_select_db($db, $connect); 

$file = fopen("oxxxkxxn.txt","r"); 

while(! feof($file)) 
{ 
$sql = "INSERT INTO xxxxx(xxxxx) VALUES ('($file)')"; //Insert every read line from txt to mysql database 
mysql_query($sql); 
} 
fclose($file); 
?> 

插入數據庫中的這些數據,但是這是行不通的。

(Resource id #4) (Resource id #4) (Resource id #4)

此錯誤。

+0

只是一個友情提示,您可能需要閱讀過此頁:[該如何對詢問指南(https://開頭stackoverflow.com/help/how-to-ask),因此您始終可以確定您的問題很容易回答並儘可能清晰。一定要包括你爲解決你遇到的問題所做的任何努力,以及當你嘗試修復這些問題時發生了什麼。另外不要忘記你的顯示代碼和任何錯誤信息! –

+0

請努力正確格式化您的代碼。另外,你說'這個錯誤',但你不列出錯誤?我們應該如何幫助解決這個錯誤? –

回答