本文介紹了如何在 zend 框架中打印精確的 sql 查詢?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我從模型中提取了以下代碼,
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.
.....
當我在 zend 中使用更新查詢時,
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']);
在這里我想知道確切的 mysql 查詢.有沒有辦法在 zend 中打印 mysql 查詢?善意的建議
Here i want to know the exact mysql query. Is there any possible way to print the mysql query in zend ? kindly advice
推薦答案
選擇對象在 Zend Framework 中具有 __toString() 方法.
Select objects have a __toString() method in Zend Framework.
來自 Zend 框架手冊:
From the Zend Framework manual:
$select = $db->select()
->from('products');
$sql = $select->__toString();
echo "$sql
";
// The output is the string:
// SELECT * FROM "products"
另一種解決方案是使用 Zend_Db_Profiler.即
An alternative solution would be to use the Zend_Db_Profiler. i.e.
$db->getProfiler()->setEnabled(true);
// your code
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);
Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
$db->getProfiler()->setEnabled(false);
http://framework.zend.com/manual/en/zend.db.select.html
這篇關于如何在 zend 框架中打印精確的 sql 查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!