Get Started

Medoo 1.4

Where Syntax

Query

Fetch

Transaction

Advanced

PDO object

Debug

Information

version: 1.4.5

debug

Output the generated SQL without execute it.

debug()
Return: Medoo object with debug mode enabled
This feature will output the generated SQL query automatically without using echo or other function. Please keep removed it when you finish debugging. And check the following code will be executed normally if this query do 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 of case, the page will execute multiply SQL queries in one request. If you just using debug() on one of query, the following functions will still be called, and cause some unexpected result.

// 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 is now became false value, because debug() ran above.
$database->update("account", [
	"level[+]" => 5,
	"post" => $post_id
], [
	"user_name" => "foo"
]);