2012-05-21 88 views
0

我想從我的數據庫返回結果,以便我可以創建一個XML文件以用於Adobe Flex,然後我將填充一個Google Map。在使用查爾斯的那一刻,我發現了以下錯誤mysql_fetch_assoc(): supplied argument is not a valid MySQL result resourcePHP:麻煩使用mysql_fetch_assoc

這裏是我的功能代碼:

public function getBusiness ($item) 
{ 
    $stmt = mysqli_prepare($this->connection, 

    "SELECT * FROM businesses"); 

    $this->throwExceptionOnError(); 

    mysqli_stmt_execute($stmt); 

    $this->throwExceptionOnError(); 

    $row = ""; 

    echo "<?xml version=\"1.0\" ?><map>"; 

    while(($row = mysql_fetch_assoc($stmt)) !== false) 
    { 
     echo "<business><businessid>" . $row["businessid"] . "</businessid>"; 
     echo "<type>" . $row["type"] . "</type>"; 
     echo "<name>" . $row["name"] . "</name>"; 
     echo "<street>" . $row["street"] . "</street>"; 
     echo "<city>" . $row["city"] . "</city>"; 
     echo "<country>" . $row["country"] . "</country>"; 
     echo "<postcode>" . $row["postcode"] . "</postcode>"; 
     echo "<latitude>" . $row["latitude"] . "</latitude>"; 
     echo "<longitude>" . $row["longitude"] . "</longitude>"; 
     echo "<phonenumber>" . $row["phonenumber"] . "</phonenumber>"; 
     echo "<email>" . $row["email"] . "</email>"; 
     echo "<website>" . $row["website"] . "</website>"; 
     echo "<logo>" . $row["logo"] . "</logo>"; 
     echo "<description>" . $row["description"] . "</description>"; 
     echo "<datesubmitted>" . $row["datesubmitted"] . "</datesubmitted></business>"; 
    } 
    echo "</map>"; 


} 

任何人可以幫助呢?

+0

的可能重複[mysql_fetch_assoc():提供的參數不是在PHP中一個有效的MySQL結果資源(http://stackoverflow.com/questions/1858304/mysql-fetch-assoc-supplied-argument-is-not-a-valid-mysql-result-resource-in-p) –

回答

0

您應該使用fetch_array()代替mysql_fetch_assoc()

5

您正在使用mysqli來運行語句,然後試圖將結果處理爲mysql?是的,這是行不通的。

使用相同擴展的功能!它們不是交叉兼容的。

+0

我很抱歉因爲遇到這個問題而尋求幫助。不過謝謝你讓我知道。 – user1077544