3

The issue is when I execute a var_dump() I receive the desired result, but when PDO handles it skips over one of the array entries it seems as I am not receive the desired result.

  $bd = $userObj->fetchPanel(array('category_id'=>$cdata['id']));
                //echo '<pre>'; var_dump($bd); echo '</pre>';die;
                $barr = array();
                if(count($bd) > 0){
                foreach($bd as $bval){
                    $barr[] = $bval['id'];              
                }}

               echo '<pre>'; var_dump(implode(',', $barr)); echo '</pre>';

var_dump() returned - string(7) "270,498" - which what is desired.

                $bragdataarr = $db->dbh->prepare("SELECT p.id,p.brag,p.brag_desc,p.brag_id,p.user_id, p.panel_id,p.domainurl,p.type,p.price FROM ".USERS_BRAG." as p left join ".USERS." as u on p.user_id=u.id WHERE u.status !=0 AND p.panel_id IN (:imp) AND p.status = :status ORDER BY p.id DESC LIMIT :lim, :page");

                echo '<pre>'; var_dump(implode(',', $barr)); echo '</pre>';

var_dump() returned - string(7) "270,498" - which what is desired.

                $imp = implode(',',$barr);

                echo '<pre>'; var_dump($imp); echo '</pre>';

var_dump() returned - string(7) "270,498" - which what is desired.

                $brgdataarr->bindValue(':imp',$imp ? $imp : "",PDO::PARAM_STR);

echo '<pre>'; var_dump($bragdataarr->bindValue(':imp',$imp ? $imp : "",PDO::PARAM_STR)); echo '</pre>';

var_dump() returned - bool(true) - which what is desired. But, what is displayed is only String '270' instead of both '270,498'. Why is this happening?

                $brgdataarr->bindValue(':status',1, PDO::PARAM_INT);                
                $brgdataarr->bindValue(':lim',$limit_start, PDO::PARAM_INT);
                $brgdataarr->bindValue(':page',$page_records, PDO::PARAM_INT);                  
                $brgdataarr->execute();                
                $brgdataarr = $brgdataarr->fetchAll(PDO::FETCH_ASSOC);

From my troubleshooting, I have found that this happens only when I use bindValue() with implode. If I include implode in the SQL statement implode works properly, but I receive empty string error when implode comes across it.

example:

 $brgdataarr = $db->dbh->prepare("SELECT p.id,p.brag,p.brag_desc,p.brag_id,p.user_id, p.panel_id,p.domainurl,p.type,p.price FROM ".USERS_BRAG." as p left join ".USERS." as u on p.user_id=u.id WHERE u.status !=0 AND p.panel_id IN (".implode(',',$barr).") AND p.status = :status ORDER BY p.id DESC LIMIT :lim, :page");
Claude Grecea
  • 543
  • 1
  • 9
  • 19

1 Answers1

0

I think it's because of your quotes around the set of integers. Moreover it is possible you have a typo on your LIMIT syntax. Let's use the standard LIMIT :limit OFFSET :offset synthax, more readable and compatible with every database.

$imp = $imp? implode(',',array_map($imp,array(PDO,'quote'))):"'-1'";

$brgdataarr = $db->dbh->prepare("SELECT p.id,p.brag,p.brag_desc,p.brag_id,p.user_id, p.panel_id,p.domainurl,p.type,p.price FROM ".USERS_BRAG." as p left join ".USERS." as u on p.user_id=u.id WHERE u.status !=0 AND p.panel_id IN (".$imp.") AND p.status = :status ORDER BY p.id DESC LIMIT :lim OFFSET :page");
artragis
  • 3,677
  • 1
  • 18
  • 30