How to print exact sql query in zend framework ?(如何在 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 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 zend 框架中打印精确的 sql 查询?


基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01