php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64132 PDO/MySQL query fails when binding a float value with data type PDO::PARAM_INT
Submitted: 2013-02-02 15:14 UTC Modified: 2016-10-10 22:28 UTC
Votes:6
Avg. Score:4.3 ± 0.7
Reproduced:5 of 6 (83.3%)
Same Version:4 (80.0%)
Same OS:2 (40.0%)
From: ipernet at gmail dot com Assigned: adambaratz (profile)
Status: Closed Package: PDO Core
PHP Version: 5.4.11 OS: Slackware 13 x64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ipernet at gmail dot com
New email:
PHP Version: OS:

 

 [2013-02-02 15:14 UTC] ipernet at gmail dot com
Description:
------------
PHP:
5.4.11

PDO Client API version:
mysqlnd 5.0.10 - 20111026 - $Id: b0b3b15c693b7f6aeb3aa66b646fee339f175e39 $ 

MySQL:
5.5.18-log

Using a PDO prepared statement to insert a new row, the query fails if a float 
value is passed for a token and this token use PDO::PARAM_INT as data type.

Test script:
---------------
CREATE TABLE IF NOT EXISTS `test` (
  `kms` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-------------------------------------------


$query	=	$dbh->prepare('INSERT INTO test(kms) VALUES(:kms)');

$query->bindValue(':kms',  1.25, PDO::PARAM_INT);
$query->execute();

var_dump($query->errorInfo());

Expected result:
----------------
- "1" should be inserted in the table
- Query should execute properly and do not lead to a SQL parsing error.

Actual result:
--------------
array(3) {
  [0] =>
  string(5) "21S01"
  [1] =>
  int(1136)
  [2] =>
  string(47) "Column count doesn't match value count at row 1"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-11 09:51 UTC] ipernet at gmail dot com
Important note:

This only happens if the set locale use a comma as decimal separator. 

Please add "setlocale(LC_ALL, 'fr_FR');" at the beginning of the test code to 
reproduce. 

This is still an unexpected behavior.
 [2013-03-12 15:23 UTC] uw@php.net
Yet another PDO core bug that is not a MySQL bug... 

PDO converts 1.25 to 1,25 as part of the statement emulation, puts 1,25 in the statement string and your query becomes INSERT INTO (col) VALUES (1,25).
 [2013-06-16 03:07 UTC] kenji dot uui at gmail dot com
Disabling emulation of prepared statements makes no error.

$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
 [2014-01-01 12:34 UTC] felipe@php.net
-Package: PDO related +Package: PDO MySQL
 [2014-03-20 16:09 UTC] uw@php.net
-Package: PDO MySQL +Package: PDO Core
 [2014-03-20 16:09 UTC] uw@php.net
PDO, not PDO MySQL bug: how can a driver be responsible for the core (ext/pdo)?
 [2016-10-10 22:28 UTC] adambaratz@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: adambaratz
 [2016-10-10 22:28 UTC] adambaratz@php.net
I had a duplicate ticket in for this issue (#73234). The fix I committed references the newer ticket.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC