Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-29-2009, 12:58 PM PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I have seen on some sites that it has a script for doing this:

7 Queries 0.40125 Execution Time


Does anybody know how to do something like that???
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 01-29-2009, 01:07 PM Re: PHP Query Results
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
You mean like this?
PHP Code:
<?php
// Insert this block of code at the very top of your page:
$time microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$start $time;

// Place this part at the very end of your page
$time microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$finish $time;
$totaltime = ($finish $start);
printf ("This page took %f seconds to load."$totaltime);
?>
- Steve

Last edited by stevej; 01-29-2009 at 01:10 PM..
stevej is offline
Reply With Quote
View Public Profile
 
Old 01-29-2009, 01:08 PM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Yeah cheers!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-29-2009, 01:08 PM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
is there any way to count the number of queries in a page???
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-29-2009, 01:27 PM Re: PHP Query Results
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Then I suppose you'll want this:
PHP Code:
<?php
// Insert this block of code at the very top of your page:
$time microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$start $time;

// You can put this anywhere you like
$GLOBALS['_MYSQL_QUERY_COUNT'] = 0;
function 
exec_mysql_query($sql)
{
++
$GLOBALS['_MYSQL_QUERY_COUNT'];
return 
mysql_query($sql);

}
// Place this part at the very end of your page
$time microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$finish $time;
$totaltime = ($finish $start);

//echo it
echo $_MYSQL_QUERY_COUNT.' Queries ';
printf ("%f Execution Time"$totaltime);dumpfi
?>
- Steve
stevej is offline
Reply With Quote
View Public Profile
 
Old 01-31-2009, 04:19 AM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I tried it with the query count and it doesnt count any queries! How come do they have to called a certain name on the variable?
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-31-2009, 12:17 PM Re: PHP Query Results
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Be sure to put the right part of the code onto the right part of the page... and this is counting mySQL queries, not some other kind of query, mind you.

- Steve
stevej is offline
Reply With Quote
View Public Profile
 
Old 01-31-2009, 12:30 PM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
if your trying to optimize your code will that function slow it down???
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-31-2009, 12:43 PM Re: PHP Query Results
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
What do you mean? This should work:

Put at the top of page,
PHP Code:
<?php
$time 
microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$start $time;
?>
And now put this at the bottom of your page:
PHP Code:
<?php
$GLOBALS
['_MYSQL_QUERY_COUNT'] = 0;
function 
exec_mysql_query($sql)
{
++
$GLOBALS['_MYSQL_QUERY_COUNT'];
return 
mysql_query($sql);

}
$time microtime();
$time explode(" "$time);
$time $time[1] + $time[0];
$finish $time;
$totaltime = ($finish $start);

echo 
$_MYSQL_QUERY_COUNT.' Queries ';
printf ("%f Execution Time"$totaltime);dumpfi
?>
I googled this and got this all off the internet, so if it doesn't work for you you can take a look at http://www.google.com/search?hl=en&c...hp&btnG=Search

- Steve
stevej is offline
Reply With Quote
View Public Profile
 
Old 01-31-2009, 01:00 PM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
yeah but i have to execute the queries using that function!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-31-2009, 02:49 PM Re: PHP Query Results
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Originally Posted by evans123 View Post
yeah but i have to execute the queries using that function!
Yep. The trick is that you must wrap the mysql_query() call into another function.
It's that function that will both increment the query count and fire the query and return the result to the caller.
To mimic the original way of mysql_query()
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-31-2009, 02:58 PM Re: PHP Query Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
It'll take longer for the code to execute won't it???
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 01-31-2009, 03:47 PM Re: PHP Query Results
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Maybe 1 or 2 milliseconds more.
Nothing compared to the time a query takes to be sent to the db engine and returned to PHP.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to PHP Query Results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37067 seconds with 12 queries