[請益] 讀取資料

看板PHP作者 (風)時間17年前 (2008/06/12 22:26), 編輯推噓2(205)
留言7則, 2人參與, 最新討論串1/2 (看更多)
請問一下 我想寫一個程式可以讀取資料庫的資料 並將讀取的資料寫入.txt檔 但是執行時會出現 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource 以下是我的程式碼,想請問是哪裡出錯 mysql_connect("localhost","root","111") or die("連接失敗"); mysql_select_db("test") or die("無法連結資料庫"); $result=mysql_query("select * from list"); while ($row=mysql_fetch_row($result)) { for ($i=0;$i<count($row);$i++) { echo $row[$i]."<br>"; } } $fp=fopen("data.txt","w+"); fputs($fp,$row[$i]); fclose($fp); 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.106.247

06/12 23:18, , 1F
你的mysql_query失敗了~檢查一下$result的錯誤訊息是什麼
06/12 23:18, 1F

06/13 00:38, , 2F
錯誤訊息是mysql_fetch_row(): supplied argument is not a
06/13 00:38, 2F

06/13 00:38, , 3F
valid MySQL result
06/13 00:38, 3F

06/13 01:40, , 4F
對~是錯在mysql_fetch_row()函式沒錯~但原因是你給他一個
06/13 01:40, 4F

06/13 01:41, , 5F
不對的參數~也就是你前一個query函式出來是不對的結果~
06/13 01:41, 5F

06/13 01:42, , 6F
你並沒有檢查mysql_query有沒有正確執行就要他fatch結果
06/13 01:42, 6F

06/13 01:43, , 7F
可能要檢查看看query function有沒有error message
06/13 01:43, 7F
文章代碼(AID): #18KJ8hC1 (PHP)
討論串 (同標題文章)
以下文章回應了本文
1
1
完整討論串 (本文為第 1 之 2 篇):
1
1
2
7
文章代碼(AID): #18KJ8hC1 (PHP)