catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

debug method suggestion #923

Closed lcsqlpete closed 3 years ago

lcsqlpete commented 4 years ago

I think it would be useful to have the option to return the output of debug into a variable, e.g. $db->debug("return")->.... In my case, the script using Medoo was invoked via an Ajax call which expected JSON to be returned so I was not able to see the debug output. This feature would give users the ability to format the debug output appropriately for their needs.

catfan commented 3 years ago

I have made a new feature for this.

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

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

var_dump($database->debugLog());

// Will out all debug logs as array
array(2) {
  [0]=> string(10) "SELECT ... FROM"
  [1]=> string(10) "UPDATE ... SET ... WHERE ..."
}