PDO Statement bindValue

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Is there a way to bind a value that contains colons?  I tried today
and it seems to think that each colon represents a different field

for example:
If I am storing serialized arrays in a mysql table and want to search
for a certain serialized array say:
array(0=>1) which when serialized becomes a:1:.

Using the query string "select * from table where response = ?" causes
an exception to be thrown.

Is there a way to achieve what I'm looking for or am I sol?


Re: PDO Statement bindValue


Quoted text here. Click to load it

Nono, that becomes a:1:  :P

Quoted text here. Click to load it

What code do you use? Semicolons & colons work fine here...

$serialized_string = serialize(array(1));
$dbh = new PDO('mysql:host=3Dlocalhost;dbname=3Dtest', $user, $pass);
$dbh->query('create table test (col text);');
$insert = $dbh->prepare('INSERT INTO test (col) VALUES (?)');
$insert->bindValue(1,$serialized_string, PDO::PARAM_STR);

$retrieve = $dbh->prepare('SELECT * FROM test WHERE col = ?');
$retrieve->bindValue(1,$serialized_string, PDO::PARAM_STR);
$dbh->query('drop table test');
array(1) {
   array(1) {
     string(14) "a:1:"

-- =

Rik Wasmus

Site Timeline