Binding parameters with $pdoObject->execute() works but bindValue() doesn't work

44 views Asked by At

bindValue() doesn't work but the query works well if I do hard cording it or use:

$pdo->execute([':s_dt'=>$a, ':e_dt'=>$b]);

What is the difference between them?

I can't show you some information, so I changed the name of values and tables.

This is the query:

select *
from (     
    select *, max(p) as tt
    from  a, c, b 
    where 1=1
            and c.cb=b.cb
            and c.a=b.a
            and dt >= :s_dt
            and dt <= :e_dt
            and a.t = "t"
            and a.s= "1"
            and a.cn= c.cn
            and a.a1=c.a1_n
            and a.a2=c.a2_n                 
            and (b.ct = 1 or b.ct2 = 1 or b.ct3= 1 )
            group by a.ct, a.ct2 a.ct3, a.t, a.a                    
) t
where 1=1
    and (t.p-t.s)  <0                       
    order by d desc , g asc

The php code that doesn't work.

$query_pdo->bindValue(':s_dt', '2019-10-02', PDO::PARAM_STR);
$query_pdo->bindValue(':e_dt', '2019-10-10', PDO::PARAM_STR);
$query_pdo->execute();

The other php code that works.

$query_pdo->execute([':s_dt'=>'2019-10-02', ':e_dt'=>'2019-10-10']);
0

There are 0 answers