class DebugPDO extends PropelPDO
PDO connection subclass that provides some basic support for query counting and logging.
This class is ONLY intended for development use. This class is also a work in-progress
and, as such, it should be expected that this class' API may change.
The following runtime configuration items affect the behaviour of this class:
- debugpdo.logging.innerglue (default: ": ")
String to use for combining the title of a detail and its value
- debugpdo.logging.outerglue (default: " | ")
String to use for combining details together on a log line
- debugpdo.logging.realmemoryusage (default: false)
Parameter to memory_get_usage() and memory_get_peak_usage() calls
- debugpdo.logging.methods (default: DebugPDO::$defaultLogMethods)
An array of method names ("Class::method") to be included in method call logging
- debugpdo.logging.onlyslow (default: false)
Suppress logging of non-slow queries.
- debugpdo.logging.details.slow.enabled (default: false)
Enables flagging of slow method calls
- debugpdo.logging.details.slow.threshold (default: 0.1)
Method calls taking more seconds than this threshold are considered slow
- debugpdo.logging.details.time.enabled (default: false)
Enables logging of method execution times
- debugpdo.logging.details.time.precision (default: 3)
Determines the precision of the execution time logging
- debugpdo.logging.details.time.pad (default: 10)
How much horizontal space to reserve for the execution time on a log line
- debugpdo.logging.details.mem.enabled (default: false)
Enables logging of the instantaneous PHP memory consumption
- debugpdo.logging.details.mem.precision (default: 1)
Determines the precision of the memory consumption logging
- debugpdo.logging.details.mem.pad (default: 9)
How much horizontal space to reserve for the memory consumption on a log line
- debugpdo.logging.details.memdelta.enabled (default: false)
Enables logging differences in memory consumption before and after the method call
- debugpdo.logging.details.memdelta.precision (default: 1)
Determines the precision of the memory difference logging
- debugpdo.logging.details.memdelta.pad (default: 10)
How much horizontal space to reserve for the memory difference on a log line
- debugpdo.logging.details.mempeak.enabled (default: false)
Enables logging the peak memory consumption thus far by the currently executing PHP script
- debugpdo.logging.details.mempeak.precision (default: 1)
Determines the precision of the memory peak logging
- debugpdo.logging.details.mempeak.pad (default: 9)
How much horizontal space to reserve for the memory peak on a log line
- debugpdo.logging.details.querycount.enabled (default: false)
Enables logging of the number of queries performed by the DebugPDO instance thus far
- debugpdo.logging.details.querycount.pad (default: 2)
How much horizontal space to reserve for the query count on a log line
- debugpdo.logging.details.method.enabled (default: false)
Enables logging of the name of the method call
- debugpdo.logging.details.method.pad (default: 28)
How much horizontal space to reserve for the method name on a log line
- debugpdo.logging.connection (default: false)
Add connectionName in log used for explains
The order in which the logging details are enabled is significant, since it determines the order in
which they will appear in the log file.
Constants
PROPEL_ATTR_CACHE_PREPARES |
Attribute to use to set whether to cache prepared statements. |
PROPEL_ATTR_CONNECTION_NAME |
Attribute to use to set the connection name usefull for explains |
DEFAULT_SLOW_THRESHOLD |
|
DEFAULT_ONLYSLOW_ENABLED |
|
Properties
boolean | $useDebug |
Methods
__construct(string $dsn, string $username = null, string $password = null, array $driver_options = array())
Creates a PropelPDO instance representing a connection to a database. |
from PropelPDO | |
setConfiguration(PropelConfiguration $configuration)
Inject the runtime configuration |
from PropelPDO | |
PropelConfiguration |
getConfiguration()
Get the runtime configuration |
from PropelPDO |
integer |
getNestedTransactionCount()
Gets the current transaction depth. |
from PropelPDO |
boolean |
isInTransaction()
Is this PDO connection currently in-transaction? This is equivalent to asking whether the current nested transaction count is greater than 0. |
from PropelPDO |
boolean |
isCommitable()
Check whether the connection contains a transaction that can be committed. |
from PropelPDO |
boolean |
beginTransaction()
Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction. |
from PropelPDO |
boolean |
commit()
Overrides PDO::commit() to only commit the transaction if we are in the outermost transaction nesting level. |
from PropelPDO |
boolean |
rollBack()
Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost transaction nesting level |
from PropelPDO |
boolean |
forceRollBack()
Rollback the whole transaction, even if this is a nested rollback and reset the nested transaction count to 0. |
from PropelPDO |
void |
setAttribute(integer $attribute, mixed $value)
Sets a connection attribute. |
from PropelPDO |
mixed |
getAttribute(integer $attribute)
Gets a connection attribute. |
from PropelPDO |
PDOStatement |
prepare(string $sql, array $driver_options = array())
Prepares a statement for execution and returns a statement object. |
from PropelPDO |
integer |
exec(string $sql)
Execute an SQL statement and return the number of affected rows. |
from PropelPDO |
PDOStatement |
query()
Executes an SQL statement, returning a result set as a PDOStatement object. |
from PropelPDO |
clearStatementCache()
Clears any stored prepared statements for this connection. |
from PropelPDO | |
integer |
getQueryCount()
Returns the number of queries this DebugPDO instance has performed on the database connection. |
from PropelPDO |
integer |
incrementQueryCount()
Increments the number of queries performed by this DebugPDO instance. |
from PropelPDO |
string |
getLastExecutedQuery()
Get the SQL code for the latest query executed by Propel |
from PropelPDO |
setLastExecutedQuery(string $query)
Set the SQL code for the latest query executed by Propel |
from PropelPDO | |
useDebug(boolean $value = true)
Enable or disable the query debug features |
from PropelPDO | |
setLogLevel(integer $level)
Sets the logging level to use for logging method calls and SQL statements. |
from PropelPDO | |
setLogger(BasicLogger $logger)
Sets a logger to use. |
from PropelPDO | |
BasicLogger |
getLogger()
Gets the logger in use. |
from PropelPDO |
log(string $msg, integer $level = null, string $methodName = null, array $debugSnapshot = null)
Logs the method call or SQL using the Propel::log() method or a registered logger class. |
from PropelPDO | |
array |
getDebugSnapshot()
Returns a snapshot of the current values of some functions useful in debugging. |
from PropelPDO |
__destruct()
If so configured, makes an entry to the log of the state of this object just prior to its destruction. |
from PropelPDO |
Details
in PropelPDO at line 146
public
__construct(string $dsn, string $username = null, string $password = null, array $driver_options = array())
Creates a PropelPDO instance representing a connection to a database.
.
If so configured, specifies a custom PDOStatement class and makes an entry
to the log with the state of this object just after its initialization.
Add PropelPDO::__construct to $defaultLogMethods to see this message
in PropelPDO at line 165
public
setConfiguration(PropelConfiguration $configuration)
Inject the runtime configuration
in PropelPDO at line 175
public PropelConfiguration
getConfiguration()
Get the runtime configuration
in PropelPDO at line 189
public integer
getNestedTransactionCount()
Gets the current transaction depth.
in PropelPDO at line 209
public boolean
isInTransaction()
Is this PDO connection currently in-transaction? This is equivalent to asking whether the current nested transaction count is greater than 0.
in PropelPDO at line 220
public boolean
isCommitable()
Check whether the connection contains a transaction that can be committed.
To be used in an evironment where Propelexceptions are caught.
in PropelPDO at line 230
public boolean
beginTransaction()
Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.
in PropelPDO at line 253
public boolean
commit()
Overrides PDO::commit() to only commit the transaction if we are in the outermost transaction nesting level.
in PropelPDO at line 282
public boolean
rollBack()
Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost transaction nesting level
in PropelPDO at line 309
public boolean
forceRollBack()
Rollback the whole transaction, even if this is a nested rollback and reset the nested transaction count to 0.
in PropelPDO at line 340
public void
setAttribute(integer $attribute, mixed $value)
Sets a connection attribute.
This is overridden here to provide support for setting Propel-specific attributes too.
in PropelPDO at line 362
public mixed
getAttribute(integer $attribute)
Gets a connection attribute.
This is overridden here to provide support for setting Propel-specific attributes too.
in PropelPDO at line 389
public PDOStatement
prepare(string $sql, array $driver_options = array())
Prepares a statement for execution and returns a statement object.
Overrides PDO::prepare() in order to:
- Add logging and query counting if logging is true.
- Add query caching support if the PropelPDO::PROPEL_ATTR_CACHE_PREPARES was set to true.
in PropelPDO at line 420
public integer
exec(string $sql)
Execute an SQL statement and return the number of affected rows.
Overrides PDO::exec() to log queries when required
in PropelPDO at line 447
public PDOStatement
query()
Executes an SQL statement, returning a result set as a PDOStatement object.
Despite its signature here, this method takes a variety of parameters.
Overrides PDO::query() to log queries when required
in PropelPDO at line 473
public
clearStatementCache()
Clears any stored prepared statements for this connection.
in PropelPDO at line 505
public integer
getQueryCount()
Returns the number of queries this DebugPDO instance has performed on the database connection.
When using DebugPDOStatement as the statement class, any queries by DebugPDOStatement instances
are counted as well.
in PropelPDO at line 522
public integer
incrementQueryCount()
Increments the number of queries performed by this DebugPDO instance.
Returns the original number of queries (ie the value of $this->queryCount before calling this method).
in PropelPDO at line 532
public string
getLastExecutedQuery()
Get the SQL code for the latest query executed by Propel
in PropelPDO at line 542
public
setLastExecutedQuery(string $query)
Set the SQL code for the latest query executed by Propel
in PropelPDO at line 552
public
useDebug(boolean $value = true)
Enable or disable the query debug features
in PropelPDO at line 571
public
setLogLevel(integer $level)
Sets the logging level to use for logging method calls and SQL statements.
in PropelPDO at line 583
public
setLogger(BasicLogger $logger)
Sets a logger to use.
The logger will be used by this class to log various method calls and their properties.
in PropelPDO at line 593
public BasicLogger
getLogger()
Gets the logger in use.
in PropelPDO at line 609
public
log(string $msg, integer $level = null, string $methodName = null, array $debugSnapshot = null)
Logs the method call or SQL using the Propel::log() method or a registered logger class.
in PropelPDO at line 657
public array
getDebugSnapshot()
Returns a snapshot of the current values of some functions useful in debugging.
in PropelPDO at line 796
public
__destruct()
If so configured, makes an entry to the log of the state of this object just prior to its destruction.
Add PropelPDO::__destruct to $defaultLogMethods to see this message