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

怎甘沉沦 提交于 2020-01-15 05:08:05

问题


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


来源:https://stackoverflow.com/questions/6712669/in-zend-how-to-print-a-mysql-query-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!