user822421
user822421

Reputation: 75

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 <= '10:40'))

in zend framework ?

Upvotes: 1

Views: 489

Answers (3)

burntblark
burntblark

Reputation: 1700

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"

Upvotes: 0

Hubidubi
Hubidubi

Reputation: 880

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'");

Upvotes: 1

JellyBelly
JellyBelly

Reputation: 2431

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'");

Upvotes: 1

Related Questions