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

2019-07-22 18:04发布

问题:

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!

回答1:

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);
      }


回答2:

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.



回答3:

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);