【问题标题】:Get finnaly sql string in Yii在 Yii 中获取 finnaly sql 字符串
【发布时间】:2013-11-21 08:40:11
【问题描述】:

我尝试使用配置获取由 CdbCriteria 创建的编译 sql 字符串:

array(
...
   'db' => array(
...
      'enableProfiling' => true,
      'enableParamLogging' => true,
   ),
...
   'log' => array(
      'class' => 'CLogRouter',
      'routes' => array(
         array(
            'class' => 'CProfileLogRoute',
            'levels' => 'profile',
            'enabled' => true,
         ),
...

但在日志中我没有得到 finnaly sql 查询,只是类似字符串

system.db.CDbCommand.query(SELECT * FROM `tourn` `t` WHERE (:tournId > 0 AND id = :tournId) AND (:userId > 0 AND user_id = :userId) LIMIT 1. Bound with :tournId='1 OR TRUE', :userId='1')

如何获得编译查询?已替换参数占位符。

【问题讨论】:

  • 我想你误解了什么是编译查询。您正在寻找的 SQL 永远不会作为字符串存在。这就是使用占位符的意义所在。
  • 嗯,好的。我刚从科哈纳来。在那里,您可以通过 Database::instance()->last_query 获得“已编译”的 sql 查询。我认为 Yii 有类似的机制。谢谢。
  • 这意味着 Kohana 要么构造了这样一个字符串(用于调试目的),要么 Kohana 存在潜在的 SQL 注入漏洞。有可能你可以以某种方式记录参数,但我不知道 yii 或 php,所以我对此无能为力。

标签: php sql yii


【解决方案1】:

扩展 Yii-Debug-Toolbar 为您提供每个请求的所有 SQL 查询:http://www.yiiframework.com/extension/yii-debug-toolbar/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 2023-01-26
    相关资源
    最近更新 更多