Introduction
PowerLitePdo provides a robust debugging system that allows developers to track and understand the execution of SQL queries. The debugging system is built around two contexts: a global context and a local context. The local context is attached to method calls like select()
, query()
, insert()
, update()
, delete()
, etc., and takes precedence over the global context.
The debugging mode can be set to three possible values: true
, false
, or 'silent'
.
true
: The class will display detailed error messages.false
: The class will not display any error messages.'silent'
: The class will register all error messages, which can be retrieved using the getDebug()
method.
When the debug
mode is enabled, the insert
, update
, and delete
statements are not executed.
Instead, the system internally uses a transaction to retrieve the debug information and then rolls back the transaction.
Debugging with the Db Class
The Db
class uses the setDebug()
method to set the global debug mode. The local debug mode can be enabled using the @param bool|string $debug
argument on method calls when available.
Here is the setDebug()
method from the Db
class:
public function setDebug($debug): self
Argument | Type | Description | Examples |
---|
$debug | bool|string | The debug mode to set. Can be true , false , or 'silent' . | true false 'silent' |
Example of using the `setDebug()` method with Db Db::setDebug()
// Enable the Debug mode globally
$db->setDebug(true);
$db->update(...); // Debug mode is enabled, the page will display the information and the update will not be executed.
$db->update(..., false); // Debug mode is disabled locally, the update will be executed and no debug information will be displayed.
Debugging with the QueryBuilder Class
The QueryBuilder
class uses the setDebug()
and debugOnce()
methods to set the global and local debug modes respectively.
Here is the setDebug()
method from the QueryBuilder
class:
public function setDebug($debug): self
Argument | Type | Description | Examples |
---|
$debug | bool|string | The debug mode to set. Can be true , false , or 'silent' . | true false 'silent' |
Example of using the `setDebug()` method with the QueryBuilder QueryBuilder::setDebug()
// Enable the Debug mode globally
$queryBuilder->setDebug(true);
Here is the debugOnce()
method from the QueryBuilder
class:
public function debugOnce($debug): self
Argument | Type | Description | Examples |
---|
$debug | bool|string | The debug mode to set for a single query. Can be true , false , or 'silent' . | true false 'silent' |
Example of using the QueryBuilder's `debugOnce()` method QueryBuilder::debugOnce()
// Enable the Debug mode locally
$queryBuilder->insert($table, $values)->debugOnce(true);
Both the Db
and QueryBuilder
classes have a getDebug()
method that returns the view of the debugging data, which includes the prepared SQL, the parameters, the final SQL, and other information.