2
votes

I am using Symfony 1.4 and Propel(ORM), i want to execute SQL query (SELECT * FROM 'myblog' WHERE 'blog_title' LIKE '%symfony%' OR 'blog_post' LIKE '%symfony%') want to get all the records from myblog which contains the word symfony. I wrote the Symfony code as,

$c = new Criteria();
$c->add(MyblogPeer::BLOG_TITLE, "%symfony%", Criteria::LIKE);
$c->addOr(MyblogPeer::BLOG_POST, "%symfony%", Criteria::LIKE);
$my_blog = MyblogPeer::doSelect($c);

but it returns a empty set. Is there any thing wrong in giving the parameter.

1

1 Answers

3
votes

I think that in order to create an OR in the where closure, you need to create a Criterion and then add that criterion to the query, it should be something like this:

$c = new Criteria();
$criterion = $c->getNewCriterion(MyblogPeer::BLOG_TITLE, "%symfony%", Criteria::LIKE);
$criterion->addOr($c->getNewCriterion(MyblogPeer::BLOG_POST, "%symfony%", Criteria::LIKE));
$c->add($criterion);
$my_blog = MyblogPeer::doSelect($c);