2

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!

Community
  • 1
  • 1
Zhaojun Zhang
  • 489
  • 4
  • 10

3 Answers3

3

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);
      }
Jan Galtowski
  • 878
  • 6
  • 8
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.

ddinchev
  • 33,683
  • 28
  • 88
  • 133
  • I am also in the same situation, i have the values with "?" or the values are in array format and not in sql statements..is there any way to have it like INSERT INTO 'table' ('','','') VALUES ('','','') – JDesigns Sep 06 '11 at 18:14
2

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);
Richard Ayotte
  • 5,021
  • 1
  • 36
  • 34