简体   繁体   English

选择Zend Db with array

[英]Select Zend Db with array

What's the correct syntax to select multiple rows through an array using Zend ? 使用Zend通过数组选择多行的正确语法是什么? So basically fetch all the data that has name $a OR $b etc..depending on number of array elements. 所以基本上获取所有名称$a OR $b等的数据。取决于数组元素的数量。 I can't figure it out....... 我无法弄明白.......

public function selectRow($array) 
{
    $data = $this->table->select()
                        ->where('name = ?', $array);
    return $this->table->fetchAll($data);
}

you can use orWhere() in the Zend_Db_Select. 你可以在Zend_Db_Select中使用orWhere() Check the manual Zend_Db_Select::where() . 检查手册Zend_Db_Select :: where()

public function selectRow($array) 
{
    $data = $this->table->select()
                        ->where('name = ?', $array)
                        ->orWhere('address = ?', $anotherarray);
    return $this->table->fetchAll($data);
}
  • it would be better to use IN and NOT IN when the where condition contains array of values 当where条件包含值数组时,最好使用INNOT IN

You have to use IN clause for that. 你必须使用IN clause So try, 所以试试吧,

$data = $this->table->select()
                    ->where('name IN (?)', $array);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM