How to use the ZF Framework database tracker

Source: Internet
Author: User
Use in learning job zend_db
Method of invoking the tracker
$Profiler = $Db-Getprofiler ();
  1. /*
  2. How to use the tracker
  3. */
  4. Introducing the loader class (auto-load Class)
  5. Require_once ("zend/loader.php");
  6. Introducing a DB class using the Loader class
  7. Zend_loader::loadclass ("zend_db");
  8. Introducing the ZEND_DB State device
  9. Zend_loader::loadclass ("Zend_db_statement_pdo");
  10. Configure Database connection Information
  11. $Config = Array (' host ' = ' 127.0.0.1 ',
  12. ' Username ' = ' root ',
  13. ' Password ' = ' 111 ',
  14. ' dbname ' = ' test ',
  15. ' Profiler ' = ' true '
  16. );
  17. Tells the zend_db class what database and database configuration information to manipulate
  18. $Db = zend_db::factory (' Pdo_mysql ', $Config);
  19. Executing an encoded statement
  20. $Db, Query ("Set names UTF8");
  21. //-----------------------------------------------------
  22. $SQL = "SELECT * from Gongsi";
  23. $Db, query ($SQL);
  24. Method of invoking the tracker
  25. $Profiler = $Db-Getprofiler ();
  26. Gets the number of bars for the commit statement
  27. echo "Number of commits:". $Profiler, Gettotalnumqueries (). "
    ";
  28. Get information on SQL statement execution
  29. $Result = $Profiler-Getqueryprofiles ();
  30. foreach ($Result as $key = $value)
  31. {
  32. Output statements that have been run
  33. echo "Text content is:". $value->getquery (). "
    ";
  34. The time it takes to output a run statement
  35. echo "Takes time:". $value->getelapsedsecs (). "
    ";
  36. }
  37. Total time spent in outputting all statements
  38. echo "Total time spent is:". $Profiler-Gettotalelapsedsecs ();
  39. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.