Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - Doctrine - or where?

I have the following query:

$query = Doctrine_Query::create()
                ->from('Member m')
                    ->where("m.type='1'")
                        ->andWhere("m.name LIKE '%$term%'")
                        ->orWhere("m.surname LIKE '%$term%'")
                        ->orWhere("m.company LIKE '%$term%'")
                        ->orderBy('id DESC');

But it's not working like I want — it is ignoring type column.

What I need is result set where m.type=1 and some of other fields in this query is LIKE 'something'.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$query = Doctrine_Query::create()
  ->from('Member m')
  ->where('m.type = 1 AND m.name LIKE ?', '%'.$term.'%')
  ->orWhere('m.type = 1 AND m.surname LIKE ?', '%'.$term.'%')
  ->orWhere('m.type = 1 AND m.company LIKE ?', '%'.$term.'%')
  ->orderBy('m.id DESC');

Your OR conditions didn't include the first condition. It's also recommended to use the ? for your variables to ensure Doctrine escapes them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...