PDO Statement bindValue

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008
Mister Joe
 
Posts: n/a
Default PDO Statement bindValue

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

Reply With Quote
  #2 (permalink)  
Old 04-11-2008
Rik Wasmus
 
Posts: n/a
Default Re: PDO Statement bindValue

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:53 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0