php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48383 PostgreSQL extension passes string param to int column when passed NULL of FALS
Submitted: 2009-05-25 10:52 UTC Modified: 2009-10-28 10:25 UTC
From: joshwaihi at gmail dot com Assigned: mbeccati (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.2.9 OS: Ubuntu
Private report: No CVE-ID: None
 [2009-05-25 10:52 UTC] joshwaihi at gmail dot com
Description:
------------
When FALSE or NULL is passed to int column, PostgreSQL 8.3 fails with the following error: Invalid text representation: 7 ERROR:  invalid input syntax for integer: ""

It would seem the PDO postgreSQL driver is passing NULL and FALSE as a string. This is not however, the case for the MySQL Driver.

Reproduce code:
---------------
try {

      $dbh = new PDO('pgsql:dbname=test;', 'myUser');
      $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $dbh->query('CREATE TABLE test (id int not null, name text not null)');

      $SQL = 'INSERT INTO test (id,name) VALUES (:id, :name)';
      $query = $dbh->prepare($SQL);
      $query->execute(array(':id' => 0, ':name' => 'This will work'));
      $query->execute(array(':id' => FALSE, ':name' => 'This will not work'));

    } catch (Exception $e) {
      print $e->getMessage();
    }

    $dbh->query('DROP TABLE test');

Expected result:
----------------
no output

Actual result:
--------------
SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for integer: ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-27 01:19 UTC] sfrost at snowman dot net
Based on what I've seen in gdb under Debian with php 5.2.9, this looks to be an issue where PHP believes it's an empty string, not a false boolean:

(gdb) p *param
$37 = {paramno = 0, name = 0x10dec80 ":id", namelen = 3, max_value_len = 0, parameter = 0x10deb10, param_type = PDO_PARAM_STR, driver_params = 0x0,
  driver_data = 0x0, stmt = 0x10dd398, is_param = 1}
(gdb) p *param->parameter
$38 = {value = {lval = 17684240, dval = 8.7371754568116058e-317, str = {val = 0x10dd710 "", len = 0}, ht = 0x10dd710, obj = {handle = 17684240,
      handlers = 0x0}}, refcount = 1, type = 6 '\006', is_ref = 0 '\0'}
(gdb) 

If param->parameter was actually coming through as a IS_BOOL, the pdo_pgsql driver would act differently (it would translate it to a 't' or an 'f' respectively, which still isn't ideal since that would still break going into an integer column, but that's easily enough fixed by switching to '1' and '0', which PG will accept as booleans directly too).
 [2009-10-28 10:25 UTC] mbeccati@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please see #44597
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 21:01:29 2024 UTC