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");