SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    monitormensch oerdec's Avatar
    Join Date
    Sep 2004
    Location
    Hamburg
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting total number of queries

    Hello,

    I´m currently writing an application where the database is affected in many different ways. There are HTML tables filled with data from the db, edit forms and stuff like that.

    OK, is there any way to get the total number of queries per page request? Unfortunately it would take too long to modify every piece of code where the database is involved... I just need a little snippet which I can place at the end of a PHP file.

    I want to see if somewhere are "too many" queries... then I´d optimise the code or rewrite it completely. BTW at this time performance is not very critical because this app will be used in an intranet only. But it could be that in future also customers and contractors are going to use it.

    oerdec


    [edit] Another thought... is there any way of seeing what happens in realtime using the command line?

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Dundee, Scotland
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only way I know of people counting queries is to have a variable doing a count every time a query has happened. Of course this is much easier to do if you are using a class to carry out the queries.

    Regarding the real time question what is it you actually want to see? top will show you the current running process' but I doubt that is what you are looking for.

  3. #3
    SitePoint Wizard Nikolas's Avatar
    Join Date
    Feb 2005
    Location
    Greece
    Posts
    1,221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't do this the way you want.

    My suggestion is to create a replacement to the mysql_query function.

    Here is a snippet :

    PHP Code:
    $totalQueries 0;
    function 
    myQuery($sql){
     global 
    $totalQueries;
     
    $totalQueries++;
     return 
    mysql_query($sql);


  4. #4
    monitormensch oerdec's Avatar
    Join Date
    Sep 2004
    Location
    Hamburg
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @filth: There are two classes that work with the db: The main database class and one for storing sessions. OK, it shouldn´t be that hard to modify these two classes... but I would like to keep them clean. I think I´ll try it anyway.

    what is it you actually want to see?
    I don´t know exactly. I have no idea how the data that is sent to the db looks like. Maybe there´s something interesting in it, like SQL.

  5. #5
    monitormensch oerdec's Avatar
    Join Date
    Sep 2004
    Location
    Hamburg
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Nikolas: Thank you for your snippet. I tried something similar but didnīt get it to function. Perhaps itīs because of all the redirections after form submissions or my brain has stopped working... Iīm coding since yesterday

    OK, I know what I have to do and Iīll try it tomorrow again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •