Zend DB 框架检查更新查询 [英] Zend DB Framework examine query for an update

查看:26
本文介绍了Zend DB 框架检查更新查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以你可以使用这样的东西:

So you can use something like this:

$query = $db->select();
$query->from('pages', array('url'));
echo $query->__toString();

检查 Zend Db 框架将用于该 SELECT 查询的 sql.是否有一种等效的方式来查看更新的 SQL?

to examine the sql that the Zend Db Framework is going to use for that SELECT query. Is there an equivilent way to view the SQL for an update?

$data = array(
   'content'      => stripslashes(htmlspecialchars_decode($content))
);      
$n = $db->update('pages', $data, "url = '".$content."'");
??

推荐答案

使用 Zend_Db_Profiler 捕获和报告 SQL 语句:

Use Zend_Db_Profiler to capture and report SQL statements:

$db->getProfiler()->setEnabled(true);
$db->update( ... );
print $db->getProfiler()->getLastQueryProfile()->getQuery();
print_r($db->getProfiler()->getLastQueryProfile()->getQueryParams());
$db->getProfiler()->setEnabled(false);

如果不需要,请记住关闭分析器!我与一位认为他有内存泄漏的人进行了交谈,但分析器为他正在运行的数百万个 SQL 查询中的每一个实例化了几个 PHP 对象.

Remember to turn the profiler off if you don't need it! I talked to one fellow who thought he had a memory leak, but it was the profiler instantiating a few PHP objects for each of the millions of SQL queries he was running.

PS:你应该使用 quoteInto() 在该查询中:

PS: You should use quoteInto() in that query:

$n = $db->update('pages', $data, $db->quoteInto("url = ?", $content));

这篇关于Zend DB 框架检查更新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆