how to write sql statement in zend framework?
How to write this sql statement
SELECT * FROM `astrology` where ((commu_time_from >= '10:30' and commu_time_from <= '10:40') or (commu_time_to >= '10:30' and commu_time_to 开发者_如何学Python<= '10:40'))
in zend framework ?
I think, this works:
$model=new Default_Model_Astronomy();
$select=$model->getMapper()->getDbTable()->getAdapter()->select();
$select=$select->from('astrology')
->where("commu_time_from >= '10:30' and commu_time_from <= '10:40'")
->orWhere("commu_time_to >= '10:30' and commu_time_to <= '10:40'");
so:
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
$select = $db->select()
->from("...specify table and columns ... ")
->where(" ...specify search criteria ... ")
->order(" ...specify sorting criteria ... ");
in your specific case:
$select = $db->select()
->from("astrology")
->where("commu_time_from >= '10:30' AND commu_time_from <= '10:40'")
->orWhere("commu_time_to >= '10:30' AND commu_time_to <= '10:40'");
Using the select object from an instance of a Zend_Db_Table ($table in my case), Try this:
$table->select()->where('(commu_time_from >= "10:30"')
->where('commu_time_from <= "10:40")')
->orWhere('(commu_time_to >= "10:30")')
->where('commu_time_to <= "10:40")')
Note that the $table variable is the instance of Zend_Db_Table with the $_name property set to "astrology"
精彩评论