Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 信条——或者在哪里?_Php_Doctrine - Fatal编程技术网

Php 信条——或者在哪里?

Php 信条——或者在哪里?,php,doctrine,Php,Doctrine,我有以下疑问: $query = Doctrine_Query::create() ->from('Member m') ->where("m.type='1'") ->andWhere("m.name LIKE '%$term%'") ->orWhere("m.surname LIKE '%$term%'

我有以下疑问:

$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');
但它并没有像我所希望的那样工作——它忽略了
type

我需要的是结果集,其中
m.type=1
,此查询中的一些其他字段是
类似“something”

$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');
您的或条件不包括第一个条件。还建议您对变量使用
,以确保规则能够避开它们。

是正确的,尽管我喜欢将代码重复/重复保持在最低限度

这种方法也应该有效,同时是一种更短、更干净的方法

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