PHP ActiveRecord: How do I add multiple conditions?

北战南征 提交于 2019-12-08 08:02:02

问题


I'm trying to bind more than one condition in php ActiveRecord

How can I change the below code (which works) to bind another condition?

$events = Event::find('all', array(
    'conditions' => array('event_type = ?', array('opera')),
    'select' => 'col1, col2, col3',
));

Thanks!


回答1:


Try this

$events = Event::find('all', array(
    'conditions' => array('event_type = ? AND event_hour = ?', 'opera', 'your_event_hour'),
    'select' => 'col1, col2, col3',
));



回答2:


$objectChanges = Table_model::update_all(array(
    'set' => array(
      'field_to_update' => 'Y'
    ),
    'conditions' => array(
      "sex= 'Male' && age <= 50"
    )
  )
);



回答3:


for example if you have use and conditions you can use

event::all(array('conditions' => array('event_type = ? AND date = ?', 'opera', '06-06-2013')));

which produce sql

SELECT * FROM event WHERE event_type = 'pera' AND date = '06-06-2013';



来源:https://stackoverflow.com/questions/16964242/php-activerecord-how-do-i-add-multiple-conditions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!