I came across this very annoying behavior, and I want to know that I am doing something wrong, or if it is intentional (and if so, why).
Whenever I have a variable in php (5.3) that is of type double, and I want to insert it into the database (MYSQL 5.0) in a field of type double, the value is always rounded to 6 digits when I use PDO. So the code below:
$stmt = $pdo->prepare("UPDATE someTable SET someDouble = :somePHPDouble;"); $number = 0.11124379542256; $stmt->bindValue(':somePHPDouble', $number); $stmt->execute();
Results at 0.111244 inserted in db. But when I passed the variable to the string (!) In the binding expression, for example:
$stmt->bindValue(':somePHPDouble', (string)$number);
he inserts it correctly as 0.11124379542256.
What's going on here? I am ignorant. MySQL datatype someDouble is really double, and when pasting it through mysql console it just works. And the variable in php is really double, so it seems to me that something is wrong inside the PDO.
Thanks in advance, -CodePoet.
source share