Snippets tagged "sql php" Snippets tagged "sql php"

[Symfony] Traiter les OR sql avec Propel

Voici comment gérer les "ou" SQL dans Propel :

$criteria = new Criteria();
$criteria->add(TotoPeer::NAME, 'Gérard Bouchard');
$criterion = $criteria->getNewCriterion (
  TotoPeer::ID, 5
)->addOr($criteria->getNewCriterion (
  TotoPeer::ID, 10
));
$criteria->addAnd($criterion);
TotoPeer::doSelect($criteria);

Ceci donnera quelque chose comme :

SELECT 
  * 
FROM 
  toto 
WHERE 
  toto.NAME = 'Gérard Bouchard' 
  AND 
  (
    toto.ID = 5 
    OR 
    toto.ID = 10
  );
by Nicolas Perriault on 2007-01-15, tagged mysql  php  propel  sql  symfony