zf架構的資料庫追蹤器使用樣本

來源:互聯網
上載者:User

 這篇文章主要介紹了zf架構的資料庫追蹤器使用樣本,現把追蹤器的使用方法分享給大家,需要的朋友可以參考下

調用追蹤器的方法  代碼如下:$Profiler = $Db -> getProfiler();  代碼如下:<?php/*追蹤器的使用方法*/ //引入Loader類(自動載入類)require_once("Zend/Loader.php");//使用Loader類引入一個Db類Zend_Loader::loadClass("Zend_Db");//引入Zend_Db的狀態器Zend_Loader::loadClass("Zend_Db_Statement_Pdo");//設定資料庫串連資訊$Config = array('host' => '127.0.0.1' ,    'username' => 'root' ,     'password' => '111' ,     'dbname' => 'test',    'profiler' => "true"    );//告訴Zend_Db類所操作的資料庫和資料庫配置資訊$Db = Zend_Db::factory('PDO_Mysql' , $Config); //執行編碼語句 $Db -> query("set names utf8");//-----------------------------------------------------$Sql = "select * from gongsi";$Db -> query($Sql);//調用追蹤器的方法$Profiler = $Db -> getProfiler();//擷取提交語句的條數echo "提交的個數:" . $Profiler -> getTotalNumQueries() . "<br>";//擷取SQL語句執行的資訊$Result = $Profiler -> getQueryProfiles();foreach ($Result as $key => $value) { //輸出運行過的語句 echo "常值內容為:" . $value->getQuery() . "<br>"; //輸出運行語句所花費的時間 echo "花費時間為:" . $value->getElapsedSecs() . "<br>";}//輸出所有語句花費的總時間echo "花費的總時間為:" . $Profiler -> getTotalElapsedSecs();?> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.