Zend framework 如何在zend框架中使用多条件选择?

Zend framework 如何在zend框架中使用多条件选择?,zend-framework,zend-db-select,Zend Framework,Zend Db Select,我想在zend framework中选择具有多个条件的行,如何实现/ 1-示例“从firstname=alex和city=xx的人员中选择id、firstname、lastname、city”; 2-示例“从firstname=alex或city=xx的人员中选择id、firstname、lastname、city” 您可以在中看到示例 //生成此查询: //选择产品标识、产品名称、价格 //来自“产品” //其中(价格500.00) //和(产品名称=‘苹果’) $minimumPrice=1

我想在zend framework中选择具有多个条件的行,如何实现/

1-示例“从firstname=alexcity=xx的人员中选择id、firstname、lastname、city”;
2-示例“从firstname=alexcity=xx的人员中选择id、firstname、lastname、city”

您可以在中看到示例

//生成此查询:
//选择产品标识、产品名称、价格
//来自“产品”
//其中(价格<100.00或价格>500.00)
//和(产品名称=‘苹果’)
$minimumPrice=100;
$maximumPrice=500;
$prod=‘苹果’;
$select=$db->select()
->来自(‘产品’,
数组('product\u id'、'product\u name'、'price'))
->其中(“价格<$minimumPrice或价格>$maximumPrice”)
->其中(‘产品名称=?’,$prod);

查看手册以查看更多示例。

在本部分“价格<$minimumPrice或价格>$maximumPrice”中,未对变量进行消毒。这可能导致SQL注入。抱歉-1。我不知道这个例子来自手册。这是错误的,但不是你的错。如果你编辑你的问题,我可以撤销投票。一方面你是正确的,但另一方面它是完全安全的,因为这两个变量都是前3行定义的,都是整数。我同意,如果有人只复制选择,这可能是个问题。为了解释如何构造查询,它更加清晰。
  // Build this query:
  //   SELECT product_id, product_name, price
  //   FROM "products"
  //   WHERE (price < 100.00 OR price > 500.00)
  //     AND (product_name = 'Apple')

  $minimumPrice = 100;
  $maximumPrice = 500;
  $prod = 'Apple';

  $select = $db->select()
               ->from('products',
                      array('product_id', 'product_name', 'price'))
               ->where("price < $minimumPrice OR price > $maximumPrice")
               ->where('product_name = ?', $prod);
$firstname = 'alex';
$city = 'xx';

// AND query
$select = $adapter->select()
    ->from('person', array('id', 'firstname', 'lastname', 'city')
    ->where('firstname = ?', $firstname)
    ->where('city ?', $city);


// OR query
$select = $adapter->select()
    ->from('person', array('id', 'firstname', 'lastname', 'city')
    ->where('firstname = ?', $firstname)
    ->orWhere('city = ?', $city);