2015-01-03 99 views
-1

我得到這個錯誤Warning: mysql_num_rows() expects parameter 1是資源,布爾在我的代碼給出低於 給出這行if(mysql_num_rows($res)>0){
請幫我警告:mysql_num_rows()預計參數1是資源,布爾在

function getProgramFee(){ 

     $sql = "SELECT program_merchantid,program_id,program_fee,program_value,program_type FROM partners_program"; 
     $res = @mysql_query($sql); 

     if(mysql_num_rows($res)>0){ 
      while($row = mysql_fetch_object($res)){ 
       $merid   = $row->program_merchantid; 
       $id   = $row->program_id; 
       $prgm_fee  = trim($row->program_fee); 
       $prgm_value = $row->program_value; 
       $prgm_type  = $row->program_type; 

       if(($prgm_type == "0")){ 
        $prgm_fee  = $program_fee; 
        $prgm_value = $program_value; 
        $prgm_type  = $program_type; 
       } 
+1

此代碼是新代碼還是舊代碼? –

+0

sir is affiliate site code http://gala-travel.com/在這裏檢查sir –

+1

這是什麼語言?你是否檢查過「$ res」中的內容? –

回答

2

作爲布爾值的參數是$resmysql_query回報FALSE上的錯誤:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

http://php.net/manual/en/function.mysql-query.php

所以問題是你的SQL查詢是無效的,也許因爲partners_program不存在或因爲其中一個字段不存在。

調試問題的一個好的開始是刪除mysql_query前面的@。 @遏制了所有的錯誤,並且一般都不贊同。如果您的PHP設置正確設置爲進行調試,則應該收到描述性錯誤消息。您也可以在mysql_query之後使用mysql_error()進行調試,以獲取更多詳細信息。

此外,mysql_*功能已被棄用了很長一段時間,所以如果可能的話,你應該檢查出pdomysqli庫。

相關問題