看板 PHP 關於我們 聯絡資訊
請問一下 我想寫一個程式可以讀取資料庫的資料 並將讀取的資料寫入.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
ianfang:你的mysql_query失敗了~檢查一下$result的錯誤訊息是什麼 06/12 23:18
bobie:錯誤訊息是mysql_fetch_row(): supplied argument is not a 06/13 00:38
bobie:valid MySQL result 06/13 00:38
ianfang:對~是錯在mysql_fetch_row()函式沒錯~但原因是你給他一個 06/13 01:40
ianfang:不對的參數~也就是你前一個query函式出來是不對的結果~ 06/13 01:41
ianfang:你並沒有檢查mysql_query有沒有正確執行就要他fatch結果 06/13 01:42
ianfang:可能要檢查看看query function有沒有error message 06/13 01:43