|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41027 Executing prepared statement changes type of bound parameters to string
Submitted: 2007-04-09 14:31 UTC Modified: 2009-10-26 22:10 UTC
Avg. Score:4.6 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: martin at bangaroo dot net Assigned:
Status: Wont fix Package: PDO related
PHP Version: 5.*, 6CVS (2009-04-27) OS: Gentoo Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: martin at bangaroo dot net
New email:
PHP Version: OS:


 [2007-04-09 14:31 UTC] martin at bangaroo dot net
Executing a prepared statement changes the type of bound parameters 
to string (Tested only with pgsql driver).

This bite me when I wanted to execute an insert statement only when 
the double value to be inserted actually changed, NULL being a 
possible value. Unfortunatly, comparing the new value with the old 
value with the !== operator didn't work, because the type-change 
made the test always evaluate to TRUE.

Reproduce code:
  $db = new PDO("pgsql:host=localhost dbname=test user=dummy");

  $db->query("CREATE TABLE test_table ( val REAL )");
  $qry = $db->prepare("INSERT INTO test_table VALUES (:val)");

  $bound_val = 5.2;
  echo "Type before execute(): ".gettype($bound_val)."\n";
  echo "Type after execute(): ".gettype($bound_val)."\n";

  $db->query("DROP TABLE test");

Expected result:
Type before execute(): double
Type after execute(): double

Actual result:
Type before execute(): double
Type after execute(): string


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-26 18:30 UTC] martin at bangaroo dot net
I just checked with the snapshot php5.2-200904261630.

Unfortunately the bug still exists.
 [2009-04-27 20:47 UTC] martin at bangaroo dot net
Same result with php5.3-200904271830:

Bug still present.
 [2009-09-22 17:57 UTC]
Thank you for your bug report.

A workaround would be to use bindValue instead of bindParam.
 [2009-10-26 22:10 UTC]
This behavior is made clear from the documentation:
- bindParam() keeps a reference to the variable
- the third parameter to bindParam() is $data_type, which defaults to PDO::PARAM_STR.

Thus, when execute() is called, the variable is changed a type of $data_type.

There does not appear to be a PDO::PARAM_FLOAT or PDO::PARAM_DOUBLE.  If that is your complaint, then please open a feature request for PDO.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 07:01:31 2024 UTC