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

2019-07-22 17:26发布

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!

3条回答
闹够了就滚
2楼-- · 2019-07-22 18:16

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);
查看更多
冷血范
3楼-- · 2019-07-22 18:21

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);
      }
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-07-22 18:24

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.

查看更多
登录 后发表回答