PHP PDO issue with float data type
When querying data from a Dolt database (version 0.40.16) using the PHP PDO library (version: PHP Version 7.2.24, PDO: mysqlnd 5.0.12-dev), I found that the float values were being rounded (mostly). Double and decimal are working as expected.
PDO+dolt Results:
| Expected Value | Output: float | Output: double | Output: decimal(5,4) |
|---|---|---|---|
| 0.5 | 0 | 0.5 | 0.5000 |
| 0.0006 | 0 | 0.0006 | 0.0006 |
| -1.5 | -2 | -1.5 | -1.5000 |
| 1.5 | 2 | 1.5 | 1.5000 |
| 1.2 | 1 | 1.2 | 1.2000 |
In conclusion the test results of various combinations within PHP:
- PDO+dolt = failure
- PDO+mariadb = success
- mysqli+dolt = success
After much trial and error I did find one PDO setting that makes the PDO+dolt work, but this is not on by default, and the PDO+mariadb did not require it.
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
At least the above setting allows us to work around this issue, and hopefully anyone else that has the similar issue can try it out as well.
Thanks for the issue and repro. We'll try and match the expected behavior.
Hi @phanxgames, thank you for the issue. I was not able to reproduce this issue. Can you give us little more details on the queries you ran to get this issue?
So far, I have tried running with and without defining PDO::ATTR_EMULATE_PREPARES, I get the expected results for having PDO::ATTR_EMULATE_PREPARES undefined or defined it as true. I was able to get this rounded float data type result only when PDO::ATTR_EMULATE_PREPARES was defined as false.
I've also tried with prepared statements using PDO's prepare method, and it gives expected results regardless of defining PDO::ATTR_EMULATE_PREPARES.
Please let me know if I'm missing or misunderstanding something here.
I'm going to close since we can't repro. Reopen if you can provide more information.