1

I have in my database an array field.

If i look i have that : a:3:{i:0;s:10:"23-09-2014";i:1;s:10:"24-09-2014";i:2;s:10:"01-10-2014";}

In my controller, i create an other array from a string with :

$array = explode(",", '01-02-2014, 02-03-2014, 03-04-2014');

I want to know, with createQueryBuilder() if all dates of my array $array are in my field in database... Like $query->where('All_my_date_in_$array ARE IN my_array_field')

Do you know a way for do that ? Thanks !

1
  • is this array has any predefined structure ? Commented Sep 23, 2014 at 18:32

1 Answer 1

2

Yes this can be possible by using wild card search on your serialized data save in your column like loop through your dates array and in loop add where clause with each data to match,this is bad because dates should saved as their real date type and for the serialized you should store it as by making relational tables for more see Database normalization

$query = $em->createQueryBuilder('u');
$i=1;
foreach($dates as $date){
if($i== 1){
         $query->where( 'u.your_column_name LIKE  :date_'.$i);
}else{
        $query->andWhere( 'u.your_column_name LIKE  :date_'.$i);
}
        $query->setParameter('date_'.$i, '%'.$date.'%');
$i++;
}
$result= $query->getQuery()
               ->getResult();

so this will match your_column_name for each date in your array with and operation and the result set will be returned which contain these dates

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.