PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Jay Gilford   Simple timer class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: Simple timer class
Measure the time that elapses
Author: By
Last change:
Date: 14 years ago
Size: 828 bytes
 

Contents

Class file image Download
<?php

include 'timer.class.php';
$db_timer = new timer();
 
// Connect to database here and create the query to be run
mysql_connect('localhost', 'root', '');
mysql_select_db('database');
 
 
$query = "SELECT * FROM table";
 
// Start timer before executing query
$db_timer->start();
$result = mysql_query($query);
 
// Pause timer
$db_timer->pause();
 
// Echo out the selected data
while($row = mysql_fetch_assoc($result)) {
    echo
print_r($row, true);
}
 
// Create another query
$query = "SELECT * FROM table2";
 
// Unpause the timer
$db_timer->pause();
 
// Execute the query
$result = mysql_query($query);
 
// Stop the timer and get the total execution time
$total_time = $db_timer->stop();
 
// Display details
echo 'SQL queries took '.$total_time.' seconds to execute in total';