ZF架構資料庫追蹤器使用方法

來源:互聯網
上載者:User
學習作業 Zend_Db中使用
//調用追蹤器的方法
$Profiler = $Db -> getProfiler();
  1. /*
  2. 追蹤器的使用方法
  3. */
  4. //引入Loader類(自動載入類)
  5. require_once("Zend/Loader.php");
  6. //使用Loader類引入一個Db類
  7. Zend_Loader::loadClass("Zend_Db");
  8. //引入Zend_Db的狀態器
  9. Zend_Loader::loadClass("Zend_Db_Statement_Pdo");
  10. //設定資料庫串連資訊
  11. $Config = array('host' => '127.0.0.1' ,
  12. 'username' => 'root' ,
  13. 'password' => '111' ,
  14. 'dbname' => 'test',
  15. 'profiler' => "true"
  16. );
  17. //告訴Zend_Db類所操作的資料庫和資料庫配置資訊
  18. $Db = Zend_Db::factory('PDO_Mysql' , $Config);
  19. //執行編碼語句
  20. $Db -> query("set names utf8");
  21. //-----------------------------------------------------
  22. $Sql = "select * from gongsi";
  23. $Db -> query($Sql);
  24. //調用追蹤器的方法
  25. $Profiler = $Db -> getProfiler();
  26. //擷取提交語句的條數
  27. echo "提交的個數:" . $Profiler -> getTotalNumQueries() . "
    ";
  28. //擷取SQL語句執行的資訊
  29. $Result = $Profiler -> getQueryProfiles();
  30. foreach ($Result as $key => $value)
  31. {
  32. //輸出運行過的語句
  33. echo "常值內容為:" . $value->getQuery() . "
    ";
  34. //輸出運行語句所花費的時間
  35. echo "花費時間為:" . $value->getElapsedSecs() . "
    ";
  36. }
  37. //輸出所有語句花費的總時間
  38. echo "花費的總時間為:" . $Profiler -> getTotalElapsedSecs();
  39. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.