#35368 [Opn->Asn]: PDO query does not work properly with serialize

From: Date: Thu, 24 Nov 2005 15:19:26 +0000
Subject: #35368 [Opn->Asn]: PDO query does not work properly with serialize
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-88856@lists.php.net to get a copy of this message
 ID:               35368
 Updated by:       tony2001@php.net
 Reported By:      lists at cyberlot dot net
-Status:           Open
+Status:           Assigned
 Bug Type:         PDO related
 Operating System: Centos 4.1
 PHP Version:      6CVS-2005-11-24 (snap)
-Assigned To:      
+Assigned To:      wez
 New Comment:

Assigned to the maintainer.


Previous Comments:
------------------------------------------------------------------------

[2005-11-24 16:07:36] lists at cyberlot dot net

Description:
------------
If you serialize a string, and run any of the escape functions,
mysql_escape, addslashes you can not use pdo->query to insert and it
does some sort of bind params translation on the string.

Bug exists in php5.1RC4 as I was using that version when I first found
this and upgraded to see if issue was resolved.

Using prepared statements ( and therefore not having to escape the data
before hand ) works.

Reproduce code:
---------------
<?

$dsn = 'mysql:dbname=alpha;host=localhost';
$login = 'alpha';
$password = 'alpha';
$db = new PDO($dsn, $login, $password);
$TEST['test']['test2'] = '1234';
$TEST['test']['test3'] = '555353';
$var = serialize($TEST);
echo "$var\n<BR>\n";
$var = mysql_escape_string($var);
$query = "INSERT INTO sessions SET value = '$var'";
$db->query($query);
$query = 'SELECT value FROM sessions';
$result = $db->query($query);
$row = $result->fetch();
echo $row[0]."\n<BR>\n";
?>


Expected result:
----------------
[root@alpha www_admin]# php index.php
a:1:{s:4:"test";a:2:{s:5:"test2";s:4:"1234";s:5:"test3";s:6:"555353";}}
<BR>
a:1:{s:4:"test";a:2:{s:5:"test2";s:4:"1234";s:5:"test3";s:6:"555353";}}
<BR>


Actual result:
--------------
[root@alpha www_admin]# php index.php
a:1:{s:4:"test";a:2:{s:5:"test2";s:4:"1234";s:5:"test3";s:6:"555353";}}
<BR>
a?:{s?:"test";a?:{s?:"test2";s?:"1234";s?:"test3";s?:"555353";}}
<BR>



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35368&edit=1


Thread (42 messages)

« previous php.bugs (#88856) next »