This is a discussion on PDO Statement bindValue within the PHP Language forums, part of the PHP Programming Forums category; Is there a way to bind a value that contains colons? I tried today and it seems to think that ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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:{i:0;s:1:"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? Thanks |
|
|||
|
On Fri, 11 Apr 2008 17:37:33 +0200, Mister Joe <mrjoefriday@gmail.com>
wrote: > 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:{i:0;s:1:"1";}. Nono, that becomes a:1:{i:0;i:1;} :P > Using the query string "select * from table where response = ?" causes > an exception to be thrown. What code do you use? Semicolons & colons work fine here... <?php //... $serialized_string = serialize(array(1)); $dbh = new PDO('mysql:host=localhost;dbname=test', $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); $insert->execute(); $retrieve = $dbh->prepare('SELECT * FROM test WHERE col = ?'); $retrieve->bindValue(1,$serialized_string, PDO::PARAM_STR); $retrieve->execute(); var_dump($retrieve->fetchAll(PDO::FETCH_ASSOC)); $dbh->query('drop table test'); ?> Output: array(1) { [0]=> array(1) { ["col"]=> string(14) "a:1:{i:0;i:1;}" } } -- Rik Wasmus |