We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

The builder is error?


    $searchinfo =array(

        );
        $listmodel = $this->modelsManager->createBuilder()
            ->from(array('c'=>'Aops\Apps\Admin\Models\CmsArticles'))
            ->columns(array('c.*'))
            ->where('c.wid = :wid:',array('wid'=>1))
            ->andWhere('c.tid = :tid:',array('tid'=>1));
        if ($searchinfo['status']!=0||empty($searchinfo['status'])){
            $listmodel->andWhere('c.status = :status:',array('status'=>1));
        } else {
            $listmodel->andWhere('c.status = :status:',array('status'=>0));
        }
            $listmodel->getQuery()->execute();
           var_dump($listmodel->getPhql());
           $rows =$this->modelsManager->executeQuery($listmodel->getPhql());
          var_dump($rows);die;

It shows "SELECT c.* FROM [Aops\Apps\Admin\Models\CmsArticles] AS [c] WHERE (c.wid = :wid: AND c.tid = :tid:) AND (c.status = :status:)",

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':wid AND c.tid = :tid) AND (c.status = :status)' at line 1

please help me!!!!!!

Just $listmodel->getQuery()->execute(); doesn't work ?



9.6k

does't work! it shows 'PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':wid AND c.tid = :tid) AND (c.status = :status)' at line 1'.....

?

use Aops\Apps\Admin\Models\CmsArticles;

$listmodel = $this->modelsManager->createBuilder()
    ->from(['c' => CmsArticles::class])
    ->columns(['c.*'])
    ->where('c.wid = :wid: AND c.tid = :tid: AND c.status = :status:', [
        'wid'    => 1,
        'tid'    => 1,
        'status' => (int) ($searchinfo['status']!=0||empty($searchinfo['status']))
    ])
    ->getQuery()
    ->execute();