2013-02-05 224 views
-3

我在下面列出的類的get_template()函數中收到上述錯誤。有誰知道我爲什麼會收到這個錯誤?所有其他查詢執行得很好,$ template_number肯定會返回一個int,這是在查詢中的這一點,所以我爲什麼會收到這個錯誤? ?難道是因爲此查詢返回在MySQL爲文本格式(和出現在phpMyAdmin一個BLOB調用成員函數的bind_param()函數調用另一個函數調用的非對象內部函數

class Page{ 

private $con; 

public function __construct(Connection $con) { 
    $this->con = $con; 
    if(isset($_GET['id'])){ 
    $id = $_GET['id']; 
    }else{  
    $id = 1; 
    }  
    $this->get_headers($id); 
    $this->get_content($id); 
    $this->get_footer($id); 
} 

private function get_headers($pageId){ 
    $retrieveHead = $this->con->prepare("SELECT headers FROM pages WHERE page_id=?"); 
    $retrieveHead->bind_param('i',$pageId); 
    $retrieveHead->execute(); 
    $retrieveHead->bind_result($header); 
    $retrieveHead->fetch(); 
    $retrieveHead->close(); 
    echo $header; 
} 

private function get_footer($pageId){ 
    $retrieveFooter = $this->con->prepare("SELECT footer FROM pages WHERE page_id=?"); 
    $retrieveFooter->bind_param('i',$pageId); 
    $retrieveFooter->execute(); 
    $retrieveFooter->bind_result($footer); 
    $retrieveFooter->fetch(); 
    $retrieveFooter->close(); 
    echo $footer; 
} 

private function get_content($pageId){ 
    $retreiveContent = $this->con->prepare("SELECT template_id, section_title, i1, i2 FROM content WHERE page_id=? ORDER BY sequence DESC"); 
    $retreiveContent->bind_param('i',$pageId); 
    $retreiveContent->execute(); 
    $retreiveContent->bind_result($template_id, $section_title, $i1, $i2); 
     while ($retreiveContent->fetch()) { 
      //Variables will be populated for this row. 
      //Update the tags in the template. 
      $template = $this->get_template($template_id); 
      $template = str_replace('[i1]',$i1,$template); 
      $template = str_replace('[i2]',$i2,$template); 
      //$theTemplate is populated with content. Probably want to echo here 
      echo $template; 
     } 
    $retreiveContent->close(); 
} 

private function get_template($template_number){ 
    $retreiveFunction = $this->con->prepare("SELECT code FROM templates WHERE template_id=?"); 
    $retreiveFunction->bind_param('i',$template_number); 
    $retreiveFunction->execute(); 
    $retreiveFunction->bind_result($template); 
    $retreiveFunction->fetch(); 
    $retreiveFunction->close(); 
    return $template; 
} 

} 

表結構可以發現如下:

Table Structure

+0

大部分的時間你可以假設'調用一個成員函數bind_param()在非object'是因爲你在'false'上調用' - > bind_param',因爲準備失敗。我假設這是因爲'$ this-> con'。你應該實現mysqli,而不是通過類。 – Amelia

+0

它適用於其他功能中的所有其他查詢,所以這不是問題。 – jezzipin

+0

錯誤包括一個行號,很遺憾您沒有提供。無論您調用的是「bind_param」,轉到該行和「var_dump」。其餘的將自行調試。 – Jon

回答

-1

對於其他人在尋找這個解決方案,因爲bwewsing建議我需要在store_result中添加上面提供的鏈接,但它不太清楚應該在哪裏實現。

執行應該在初始調用方法中進行。因此,隨着get_content()方法調用get_template()方法,這裏應該實現以下方式:

private function get_content($pageId){ 
    $retreiveContent = $this->con->prepare("SELECT template_id, section_title, i1, i2 FROM content WHERE page_id=? ORDER BY sequence DESC"); 
    $retreiveContent->bind_param('i',$pageId); 
    $retreiveContent->execute(); 
    $retreiveContent->bind_result($template_id, $section_title, $i1, $i2); 
    $retreiveContent->store_result(); 
     while ($retreiveContent->fetch()) { 
      //Variables will be populated for this row. 
      //Update the tags in the template. 
      $template = $this->get_template($template_id); 
      $template = str_replace('[i1]',$i1,$template); 
      $template = str_replace('[i2]',$i2,$template); 
      //$theTemplate is populated with content. Probably want to echo here 
      echo $template; 
     } 
    $retreiveContent->free_result();  
    $retreiveContent->close(); 
} 
1

hereheremysqli_stmt::execute()默認情況下存儲結果服務器端並逐行讀取,除非您調用mysqli_stmt::store_result()將它們緩衝到客戶端。嘗試準備另一個語句很有可能會失敗,而前一條語句存在未提取的reults服務器端

相關問題