ID: 44433 Updated by: [EMAIL PROTECTED] Reported By: hans at velum dot net -Status: Open +Status: Verified Bug Type: PDO related Operating System: Gentoo Linux PHP Version: 5.2.5
Previous Comments: ------------------------------------------------------------------------ [2008-03-13 18:30:19] hans at velum dot net 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 this bug report at http://bugs.php.net/?id=44433&edit=1