开发者

In zend, how to print a mysql query properly? [duplicate]

This question already has answers here: 开发者_开发百科 Closed 11 years ago.

Possible Duplicate:

How to print exact sql query in zend framework ?

In zend profiler, I can only either print the query with question markers (getQuery) or print the parameter array (getQueryParams).

Is there a way to replace all question markers, and print the real sql query?

Thanks!


Something like that should work:

$profile = $this->getQueryProfile($queryId);
$query = $profile->getQuery();
$params = $profile->getQueryParams();

      foreach ($params as $par) {
            $query = preg_replace('/\\?/', "'" . $par . "'", $query, 1);
      }


The framework uses prepared statements so actually this is the real query - in reality its send to the database which parses it and then the params are binded to it and executed.


You can use the __toString() method.

$dbTable = new Application_Model_DbTable_TradeshowBooking();
$select = $dbTable->select();
$select->setIntegrityCheck(false);
$select->where('ends_on + INTERVAL 4 WEEK > ? ', $requestParams['ends_on']);        

Zend_Registry::get('logger')->log($select->__toString(), Zend_Log::INFO);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜