php - How to profile SQL queries in MVC framework? -


I am working on my own php MVC framework. I just wanted to get my thoughts about all the profiles running on my profiles, I had other profiling material but I do not know how to profile SQL queries, also to see if They change profiles.

Thanks

It depends on how much information you really want , But to generate some generic for you, I will consider some of this (this class to which you are using to interact with the database):

  & lt ;? Php // Your Database Access Class Class DB {// Profiling Data Private $ sqlDataProfile = array (); Function query ($ sql) {$ starttime = time (); // Get the time before the query // query and start here profiles here whatnot //: $ this-> AddSqlProfile ($ sql, $ starttime); } // Get the total number of queries to calculate the getNumberOfQueries () (return calculation ($ this-> sqlDataProfile);} Personal function addSqlProfile ($ sql, $ starttime) {// Temporary Array $ tempArr = Create array ('Sql' = & gt; $ sql, 'time' => time () - $ starttime); // sqlDataProfile var $ this-> sqlDataProfile [] = push $ tempArr for tempArr;} } $ Db = new db; $ db- & gt; query ('SELECT * FROM table'); echo $ db-> getNumberOfQueries ();? & Gt; This is clearly a very simple example, but in this way Both will be very easy, as well as things For example, you can also keep the number of affected rows from the query, a query touch, the number of tables, etc. 


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -