PDO Statement bindValue
am 11.04.2008 17:37:33 von Mister Joe
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
Re: PDO Statement bindValue
am 11.04.2008 20:16:30 von luiheidsgoeroe
On Fri, 11 Apr 2008 17:37:33 +0200, Mister Joe =
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=3D>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 =3D ?" caus=
es
> an exception to be thrown.
What code do you use? Semicolons & colons work fine here...
//...
$serialized_string =3D serialize(array(1));
$dbh =3D new PDO('mysql:host=3Dlocalhost;dbname=3Dtest', $user, $pass);
$dbh->query('create table test (col text);');
$insert =3D $dbh->prepare('INSERT INTO test (col) VALUES (?)');
$insert->bindValue(1,$serialized_string, PDO::PARAM_STR);
$insert->execute();
$retrieve =3D $dbh->prepare('SELECT * FROM test WHERE col =3D ?');
$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]=3D>
array(1) {
["col"]=3D>
string(14) "a:1:{i:0;i:1;}"
}
}
-- =
Rik Wasmus