Skip to content
Advertisement

“bindParam” with multi-parameters after “Limit” couldn’t work in php?

I have encounterd this problem and can’t find a solution, Can some expert help me here?

public  function getComments($postId,$pageCmt){
        $db = $this->dbConnect();
        $cmtNb=3;
        $r=($pageCmt-1)*3;

        $req = $db->prepare('SELECT id, comments FROM comments WHERE post_id = ? ORDER BY ind_date DESC,date_comments DESC LIMIT ? OFFSET ?' );

        $req->bindParam(1,$postId,PDO::PARAM_INT);         
        $req->bindParam(2,$cmtNb,PDO::PARAM_INT );                 
        $req->bindParam(3,$r,PDO::PARAM_INT);

         $req->execute(array($postId,$cmtNb,$r));

         return $req;
      }

It seems the problems comme from the parameter after LIMIT, coz if i take off ” LIMIT ? OFFSET ?” the codes can work with the first parameter $postId, comments will be fetched,

But if i add the codes with “LIMIT ? OFFSET?” on the page there will be no comments fetched but no error showed neither,

Any idea?.

Thanks.

Advertisement

Answer

I Got the Solution today:

By using still ” LIMIT ? OFFSET ?” and then:

      $req->bindValue(1,$postId,PDO::PARAM_INT);          
      $req->bindValue(2,$cmtNb,PDO::PARAM_INT );               
      $req->bindValue(3,$r,PDO::PARAM_INT);
      var_dump($r);

      $req->execute(); 

It works perfectly today!, thanks you guys.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement