简体   繁体   中英

How to make zend to set time_zone in sql

I tried to execute a sql query that contains set time_zone='+8:00'; in zend, but couldn't execute it because of this string.

How do I make so that it run the query properly?

Code:

    $sql = "set time_zone='+8:00';
            SELECT
            n.id,
            ...";
    $query=$this->_db->query($sql);
    $fetch=$query->fetchAll();

    return $fetch;

You should separate the two queries. The Zend_Db objects aren't retrieving any results if you first use mysql SET command, or execute two queries at once

First use:

$this->_db->query('set time_zone='+8:00';'); 

Then, on a second line:

$Query = $this->_db->query('SELECT n.id FROM ...')

And then you can fetch results or loop through them

while($Result = $Query->fetch()) {
    print_r($Result);
}

Or use

$Query->fetchAll()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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