-3

以下にリストされているクラスの get_template() 関数で上記のエラーを受け取りました。このエラーが発生する理由を知っている人はいますか? 他のすべてのクエリは正常に実行され、$template_number は確実に int を返しますが、これはクエリのこの時点で予想されるのに、なぜこのエラーが発生するのでしょうか? このクエリの戻り値が MySQL では TEXT としてフォーマットされている (PHPMyAdmin では BLOB として表示される) ためでしょうか?

    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;
}

}

テーブル構造は以下のとおりです。

テーブル構造

4

2 に答える 2

1

ここここを参照してください。デフォルトでは、結果をサーバー側に保存し、クライアント側でバッファリングするようにmysqli_stmt::execute()呼び出しない限り、行ごとにフェッチします。mysqli_stmt::store_result()前のステートメントからサーバー側にフェッチされていない結果がある場合、別のステートメントを準備しようとすると、ほとんどの場合失敗します。

于 2013-02-06T08:33:33.627 に答える
-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();
}
于 2013-02-06T20:01:06.723 に答える