How to print exact sql query in zend framework ?

2019-01-16 03:21发布

I have the following piece of code which i taken from model,

    ...
                  $select = $this->_db->select()
                    ->from($this->_name)
                    ->where('shipping=?',$type)
                    ->where('customer_id=?',$userid);
                 echo  $select; exit; // which gives exact mysql query.
            .....

When i use update query in zend like ,

$up_value = array('billing'=> '0');
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);      

Here i want to know the exact mysql query. Is there any possible way to print the mysql query in zend ? kindly advice

13条回答
女痞
2楼-- · 2019-01-16 03:41

Use this:-

echo $select->query();

or

Zend_Debug::dump($select->query();
查看更多
Viruses.
3楼-- · 2019-01-16 03:42

You can use Zend_Debug::Dump($select->assemble()); to get the SQL query.

Or you can enable Zend DB FirePHP profiler which will get you all queries in a neat format in Firebug (even UPDATE statements).

EDIT: Profiling with FirePHP also works also in FF6.0+ (not only in FF3.0 as suggested in link)

查看更多
闹够了就滚
4楼-- · 2019-01-16 03:44

even shorter:

echo $select->__toString()."\n";

and more shorter:

echo  $select .""; die;
查看更多
Viruses.
5楼-- · 2019-01-16 03:51

Now on Zend2:

$select->getSqlString();

Displaying the generated SQL from ZendDbSql object

查看更多
倾城 Initia
6楼-- · 2019-01-16 03:52

you can print..

print_r($select->assemble());
查看更多
Viruses.
7楼-- · 2019-01-16 03:54

Check out the Zend_Db_Profiler. This allows you to log any SQL statement as it is prepared and executed. It works for UPDATE statements as well as SELECT queries.

查看更多
登录 后发表回答