From: hans at velum dot net Operating system: Gentoo Linux PHP version: 5.2.5 PHP Bug Type: PDO related Bug description: Text with null characters (\0) truncated when bound to prepared statement
Description: ------------ I'm using PostgreSQL (8.2.x) and am having a problem inserting serialized data containing null characters (\0) into the database. I am using prepared statements and the bindValue() method to bind the serialized data as a PDO::PARAM_STR. It's not obvious from the output below, but these serialized strings contain null values because of the private variables. I can't seem to find an existing bug for this; however, it surprises me that no one has reported this before. Reproduce code: --------------- $pdo = new PDO('pgsql: dbname=testdb user=postgres'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $pdo->exec('DROP TABLE testtbl'); } catch (PDOException $x) { /* ignore */ } $pdo->exec('CREATE TABLE testtbl (id integer not null, txtcol text)'); class MyClass { private $var1; function __construct($val) { $this->var1 = $val; } } $serialized = serialize(array('foo' => new MyClass('bar'), 'baz' => new MyClass('bingo!'))); print "Serialized data: " . $serialized . PHP_EOL; $stmt = $pdo->prepare('INSERT INTO testtbl (id, txtcol) VALUES (1, ?)'); $stmt->bindValue(1, $serialized, PDO::PARAM_STR); $stmt->execute(); $stmt = $pdo->query('SELECT * FROM testtbl WHERE id = 1'); $row = $stmt->fetch(); print "From database: " . $row['txtcol'] . PHP_EOL; Expected result: ---------------- Serialized data: a:2:{s:3:"foo";O:7:"MyClass":1:{s:13:"MyClassvar1";s:3:"bar";}s:3:"baz";O:7:"MyClass":1:{s:13:"MyClassvar1";s:6:"bingo!";}} >From database: a:2:{s:3:"foo";O:7:"MyClass":1:{s:13:"MyClassvar1";s:3:"bar";}s:3:"baz";O:7:"MyClass":1:{s:13:"MyClassvar1";s:6:"bingo!";}} Actual result: -------------- Serialized data: a:2:{s:3:"foo";O:7:"MyClass":1:{s:13:"MyClassvar1";s:3:"bar";}s:3:"baz";O:7:"MyClass":1:{s:13:"MyClassvar1";s:6:"bingo!";}} >From database: a:2:{s:3:"foo";O:7:"MyClass":1:{s:13:" -- Edit bug report at http://bugs.php.net/?id=44433&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44433&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44433&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44433&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44433&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44433&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44433&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44433&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44433&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44433&r=support Expected behavior: http://bugs.php.net/fix.php?id=44433&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44433&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44433&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44433&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44433&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44433&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44433&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44433&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44433&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44433&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44433&r=mysqlcfg