Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Management

Advanced

Raw object

PDO object

Debug

Information

version: 2.1.12

debug

Enable debug mode and output readable statement string.

debug()
Return: [object] Medoo object with debug mode enabled.
This feature will output the generated SQL query automatically without using echo or other functions. Please keep it removed when you finish debugging, and check if the following code will be executed normally if this query does not be executed.

Basic Usage

Output the generated SQL.

$database->debug()->select("bccount", [
	"user_name",
	"email"
], [
	"user_id[<]" => 20
]);

// Will output:
// SELECT "user_name","email" FROM "bccount" WHERE "user_id" < 20

Dangerous Case

In some cases, the page will execute multiple SQL queries in one request. If you use debug() on one of the queries, the following functions will still be called and cause some unexpected results.

// This output nothing
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com"
]);

// Will output the generated query
$post_id = $database->debug()->get("post", "post_id", ["user_name" => "foo"]);

// Be careful, this query will be executed! $post_id has now become a false value because debug() ran above.
$database->update("account", [
	"level[+]" => 5,
	"post" => $post_id
], [
	"user_name" => "foo"
]);

Debug Logging

To debug the whole or part of your project without putting debug() to every call, you can use beginDebug() to start to debug logging, and then call debugLog() to stop it and get all debug logs as an array.

// Begin debug logging
$database->beginDebug();

// All those functions will not be executed but will save it as a debug log.
$database->select()......
$database->update()......

// Call debugLog() to stop debug logging and return all debug logs as an array.
var_dump($database->debugLog());

// Will output:
array(2) {
  [0]=> string(10) "SELECT ... FROM"
  [1]=> string(10) "UPDATE ... SET ... WHERE ..."
}