ID: 48383 Updated by: [email protected] Reported By: joshwaihi at gmail dot com -Status: Assigned +Status: Bogus Bug Type: PDO related Operating System: Ubuntu PHP Version: 5.2.9 Assigned To: mbeccati New Comment:
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 Previous Comments: ------------------------------------------------------------------------ [2009-05-27 01:19:17] 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-05-25 10:52:53] 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: "" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48383&edit=1
