Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Zend_Db_Profiler Class Reference

Public Member Functions

 __construct ($enabled=false)
 Class constructor.
 
 setEnabled ($enable)
 Enable or disable the profiler.
 
 getEnabled ()
 Get the current state of enable.
 
 setFilterElapsedSecs ($minimumSeconds=null)
 Sets a minimum number of seconds for saving query profiles.
 
 getFilterElapsedSecs ()
 Returns the minimum number of seconds for saving query profiles, or null if query profiles are saved regardless of elapsed time.
 
 setFilterQueryType ($queryTypes=null)
 Sets the types of query profiles to save.
 
 getFilterQueryType ()
 Returns the types of query profiles saved, or null if queries are saved regardless of their types.
 
 clear ()
 Clears the history of any past query profiles.
 
 queryClone (Zend_Db_Profiler_Query $query)
 Clone a profiler query.
 
 queryStart ($queryText, $queryType=null)
 Starts a query.
 
 queryEnd ($queryId)
 Ends a query.
 
 getQueryProfile ($queryId)
 Get a profile for a query.
 
 getQueryProfiles ($queryType=null, $showUnfinished=false)
 Get an array of query profiles (Zend_Db_Profiler_Query objects).
 
 getTotalElapsedSecs ($queryType=null)
 Get the total elapsed time (in seconds) of all of the profiled queries.
 
 getTotalNumQueries ($queryType=null)
 Get the total number of queries that have been profiled.
 
 getLastQueryProfile ()
 Get the Zend_Db_Profiler_Query object for the last query that was run, regardless if it has ended or not.
 

Public Attributes

const CONNECT = 1
 A connection operation or selecting a database.
 
const QUERY = 2
 Any general database query that does not fit into the other constants.
 
const INSERT = 4
 Adding new data to the database, such as SQL's INSERT.
 
const UPDATE = 8
 Updating existing information in the database, such as SQL's UPDATE.
 
const DELETE = 16
 An operation related to deleting data in the database, such as SQL's DELETE.
 
const SELECT = 32
 Retrieving information from the database, such as SQL's SELECT.
 
const TRANSACTION = 64
 Transactional operation, such as start transaction, commit, or rollback.
 
const STORED = 'stored'
 Inform that a query is stored (in case of filtering)
 
const IGNORED = 'ignored'
 Inform that a query is ignored (in case of filtering)
 

Protected Attributes

 $_queryProfiles = array()
 
 $_enabled = false
 
 $_filterElapsedSecs = null
 
 $_filterTypes = null
 

Constructor & Destructor Documentation

__construct (   $enabled = false)

Class constructor.

The profiler is disabled by default unless it is specifically enabled by passing in $enabled here or calling setEnabled().

Parameters
boolean$enabled
Returns
void

Member Function Documentation

clear ( )

Clears the history of any past query profiles.

This is relentless and will even clear queries that were started and may not have been marked as ended.

Returns
Zend_Db_Profiler Provides a fluent interface
getEnabled ( )

Get the current state of enable.

If True is returned, the profiler is enabled.

Returns
boolean
getFilterElapsedSecs ( )

Returns the minimum number of seconds for saving query profiles, or null if query profiles are saved regardless of elapsed time.

Returns
integer|null
getFilterQueryType ( )

Returns the types of query profiles saved, or null if queries are saved regardless of their types.

Returns
integer|null
See Also
Zend_Db_Profiler::setFilterQueryType()
getLastQueryProfile ( )

Get the Zend_Db_Profiler_Query object for the last query that was run, regardless if it has ended or not.

If the query has not ended, its end time will be null. If no queries have been profiled, false is returned.

Returns
Zend_Db_Profiler_Query|false
getQueryProfile (   $queryId)

Get a profile for a query.

Pass it the same handle that was returned by queryStart() and it will return a Zend_Db_Profiler_Query object.

Parameters
integer$queryId
Exceptions
Zend_Db_Profiler_Exception
Returns
Zend_Db_Profiler_Query
See Also
Zend_Db_Profiler_Exception
getQueryProfiles (   $queryType = null,
  $showUnfinished = false 
)

Get an array of query profiles (Zend_Db_Profiler_Query objects).

If $queryType is set to one of the Zend_Db_Profiler::* constants then only queries of that type will be returned. Normally, queries that have not yet ended will not be returned unless $showUnfinished is set to True. If no queries were found, False is returned. The returned array is indexed by the query profile handles.

Parameters
integer$queryType
boolean$showUnfinished
Returns
array|false
getTotalElapsedSecs (   $queryType = null)

Get the total elapsed time (in seconds) of all of the profiled queries.

Only queries that have ended will be counted. If $queryType is set to one or more of the Zend_Db_Profiler::* constants, the elapsed time will be calculated only for queries of the given type(s).

Parameters
integer$queryTypeOPTIONAL
Returns
float
getTotalNumQueries (   $queryType = null)

Get the total number of queries that have been profiled.

Only queries that have ended will be counted. If $queryType is set to one of the Zend_Db_Profiler::* constants, only queries of that type will be counted.

Parameters
integer$queryTypeOPTIONAL
Returns
integer
queryClone ( Zend_Db_Profiler_Query  $query)

Clone a profiler query.

Parameters
Zend_Db_Profiler_Query$query
Returns
integer or null
queryEnd (   $queryId)

Ends a query.

Pass it the handle that was returned by queryStart(). This will mark the query as ended and save the time.

Parameters
integer$queryId
Exceptions
Zend_Db_Profiler_Exception
Returns
string Inform that a query is stored or ignored.
See Also
Zend_Db_Profiler_Exception
Zend_Db_Profiler_Exception

If filtering by elapsed time is enabled, only keep the profile if it ran for the minimum time.

If filtering by query type is enabled, only keep the query if it was one of the allowed types.

queryStart (   $queryText,
  $queryType = null 
)

Starts a query.

Creates a new query profile object (Zend_Db_Profiler_Query) and returns the "query profiler handle". Run the query, then call queryEnd() and pass it this handle to make the query as ended and record the time. If the profiler is not enabled, this takes no action and immediately returns null.

Parameters
string$queryTextSQL statement
integer$queryTypeOPTIONAL Type of query, one of the Zend_Db_Profiler::* constants
Returns
integer|null
See Also
Zend_Db_Profiler_Query
setEnabled (   $enable)

Enable or disable the profiler.

If $enable is false, the profiler is disabled and will not log any queries sent to it.

Parameters
boolean$enable
Returns
Zend_Db_Profiler Provides a fluent interface
setFilterElapsedSecs (   $minimumSeconds = null)

Sets a minimum number of seconds for saving query profiles.

If this is set, only those queries whose elapsed time is equal or greater than $minimumSeconds will be saved. To save all queries regardless of elapsed time, set $minimumSeconds to null.

Parameters
integer$minimumSecondsOPTIONAL
Returns
Zend_Db_Profiler Provides a fluent interface
setFilterQueryType (   $queryTypes = null)

Sets the types of query profiles to save.

Set $queryType to one of the Zend_Db_Profiler::* constants to only save profiles for that type of query. To save more than one type, logical OR them together. To save all queries regardless of type, set $queryType to null.

Parameters
integer$queryTypesOPTIONAL
Returns
Zend_Db_Profiler Provides a fluent interface

Member Data Documentation

$_enabled = false
protected
$_filterElapsedSecs = null
protected
$_filterTypes = null
protected
$_queryProfiles = array()
protected
const CONNECT = 1

A connection operation or selecting a database.

const DELETE = 16

An operation related to deleting data in the database, such as SQL's DELETE.

const IGNORED = 'ignored'

Inform that a query is ignored (in case of filtering)

const INSERT = 4

Adding new data to the database, such as SQL's INSERT.

const QUERY = 2

Any general database query that does not fit into the other constants.

const SELECT = 32

Retrieving information from the database, such as SQL's SELECT.

const STORED = 'stored'

Inform that a query is stored (in case of filtering)

const TRANSACTION = 64

Transactional operation, such as start transaction, commit, or rollback.

const UPDATE = 8

Updating existing information in the database, such as SQL's UPDATE.