views:

578

answers:

1

I would like to use mysql query profiler in the php script. So that after i execute any queries it need to display the execution time of the query.

Suggest the best way to use this also share any other scripts like query profiler.

+1  A: 

set profiling to 1 before the start of your script

$mysqliObj->query("SET profiling = 1");

Right after the executing the query which you want to profile, execute the following one

$mysqliObj->query("SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;")
rubayeet
Thanks for the reply rubayeet. But im not able to create a two db connections. ANy solution ?
Webrsk
What would you use the second db connection for? $mysqliObj in rubayeet example would be the same db object you use throughout your scripts
VolkerK
Now i have fixed it. I created another user and connected to the information_schema database. Now the database is connected. But the results were empty no records got inserted in the profiling table. How to make sure profiling is set ?
Webrsk
VolkerK , I created another db object to use for setting the profiling and to get results from profiling table.
Webrsk
I am able to see the profiling results in mysql client but im not able to get the results from the php script.Is it set profiling needs any permission to execute from php script ?
Webrsk
When you create the mysqli object, don't supply the dbname parameter, instead switch between your db and information_schema using mysqli::select_db() method.
rubayeet