1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Show Number of MySQL Queries

Discussion in 'PHP' started by bobby9101, May 4, 2006.

  1. #1
    CAn anyone point me in a direction for showing how many MySQL queries were run?
    Example: http://neowin.net/#aa064b58 look at the very bottom of the page it says "4 queries run"
     
    bobby9101, May 4, 2006 IP
  2. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #2
    "status" will show you queries

    example

    mysql> status
    --------------
    Threads: 104 Questions: 2800453 Slow queries: 114 Opens: 1197 Flush tables: 1 Open tables: 1024 Queries per second avg: 70.062
    --------------

    mysql>
     
    Shoemoney, May 4, 2006 IP
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i want just queries
     
    bobby9101, May 4, 2006 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Several ways

    If its like me, I dont mean to leave them there, I add a one every time I create a query, so I can keep an eye, make sure I dont do too many.

    You could also have a var set up

    At the top $num_queries = 0;

    Each query just add $num_queries = $num_queries +1;

    This will make it dynamic

    Then echo $num_queries;

    The Dynamic Way
     
    onlyican.com, May 4, 2006 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's their CMS or custom script simply counting how many queries they needed to get the info for that page.
     
    exam, May 4, 2006 IP
  6. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thier forum does it too (their forum is IPB)
     
    bobby9101, May 4, 2006 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    There's no way of telling this without counting it yourself.

    That's the basic answer.

    If you think about it, how would it work anyway? All the MySQL server knows is that it's being asked for information. It has no idea that a PHP script is requesting it, let alone which of maybe dozens of running scripts are making the request...
     
    TwistMyArm, May 4, 2006 IP
  8. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok thanks
    (i am a php n00b)
     
    bobby9101, May 4, 2006 IP
  9. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you use something like
    $queryx for your queries, where X is a number

    Then count how many times $query is on the page
     
    onlyican.com, May 4, 2006 IP
  10. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Sorry, you can count the amount of times mysql_query is shown
     
    onlyican.com, May 4, 2006 IP
  11. Edmunds

    Edmunds Peon

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Btw, counting the queries is easy if you use a database abstraction layer. You can also count how long the queries take. In fact, it's required for any programmer to make sure you don't do something stooopid. I do it all the time.
     
    Edmunds, May 5, 2006 IP
  12. gigpayrr

    gigpayrr Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    if still some one is looking for an answer, here you go, stackoverflow.com/questions/830489/how-can-i-count-the-total-number-of-mysql-queries-used-per-page
     
    gigpayrr, Sep 28, 2012 IP