我用它来检索数据库连接atm.
$db = Zend_Db_Table::getDefaultAdapter();
我在我的配置中设置了这样:
resources.db.adapter = pdo_MysqL resources.db.isDefaultTableAdapter = true resources.db.params.host = localhost resources.db.params.username = root resources.db.params.password = password resources.db.params.dbname = db resources.db.params.profiler.enabled = true resources.db.params.profiler.class = Zend_Db_Profiler
我想将所有内容输出到sql.log中.这可以应用于默认适配器吗?例如通过设置,所以我可以在生产环境中忽略它?
非常感兴趣.
我确实看过:How to enable SQL output to log file with Zend_Db?,但它似乎没有涵盖我的问题.
/马库斯
有一个扩展Zend_Db_Profiler的示例,因此您可以将查询写入/logs/db-queries.log文件.
原文链接:https://www.f2er.com/php/133773.html所以你必须做以下事情:
>在库文件夹中创建My_Db_Profiler_Log类
>将以下行添加到application.ini
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = My_Db_Profiler_Log
注意:请注意,日志文件会很快变大!因此,最好只记录您感兴趣的查询.此示例应仅被视为实现此类日志记录系统的起点.
<?PHP class My_Db_Profiler_Log extends Zend_Db_Profiler { /** * Zend_Log instance * @var Zend_Log */ protected $_log; /** * counter of the total elapsed time * @var double */ protected $_totalElapsedTime; public function __construct($enabled = false) { parent::__construct($enabled); $this->_log = new Zend_Log(); $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/logs/db-queries.log'); $this->_log->addWriter($writer); } /** * Intercept the query end and log the profiling data. * * @param integer $queryId * @throws Zend_Db_Profiler_Exception * @return void */ public function queryEnd($queryId) { $state = parent::queryEnd($queryId); if (!$this->getEnabled() || $state == self::IGNORED) { return; } // get profile of the current query $profile = $this->getQueryProfile($queryId); // update totalElapsedTime counter $this->_totalElapsedTime += $profile->getElapsedSecs(); // create the message to be logged $message = "\r\nElapsed Secs: " . round($profile->getElapsedSecs(),5) . "\r\n"; $message .= "Query: " . $profile->getQuery() . "\r\n"; // log the message as INFO message $this->_log->info($message); } } ?>