Pdo results with bound values are different than hard coded values.
$q = $conn->prepare('SELECT 0.27 * 0.08 * SUM(n) as ok,
:i * SUM(n) as notOK
from mytable
group by id');
$q->bindValue(':i', 0.27*0.08, PDO::PARAM_STR); // tax
$q->execute();
var_dump($q->fetchAll(PDO::FETCH_ASSOC));
Results:
["ok"]=> "313.095888"
["notOK"]=> "289.9036"
["ok"]=> "80.601048"
["notOK"]=> "74.6306"
...
ok != notOK, but it should (ok is correct).
My question is why?
details, what you asked for:
- column 'n' and 'id' is int
- tested on php7.4 + pdo for mssql (both linux and win)
- it works with PDO::PARAM_INT (thanks for the suggestion :), although the suggested bind type is PDO::PARAM_STR for decimal PDO::PARAM for type decimal? )