ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:debug

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:userguide:debug [2023/04/08 12:39] – [Usage] revised example following 5.23 refactoring of _adodb_debug_execute(). Note: removed paragraph on STDERR output, I don't think we actually do that anymore dregadv5:userguide:debug [2024/01/09 11:20] (current) – [Description] link to Logging page dregad
Line 8: Line 8:
  
 ===== Description ===== ===== Description =====
-Enabling debug mode makes the driver return copious amounts of debugging information from both ADOdb and the PHP driver itself. Information is displayed on both standard output (STDOUT) and standard error (STDERRchannels+ 
 +Enabling debug mode makes the driver return debugging information from both ADOdb and the PHP driver itself. 
 + 
 +The output includes the executed SQL statement with parameters, as well as error messages and backtrace information if there are problems. 
 +It is suitable for viewing in a browser (see [[#formatting|Formatting section below]] 
 + 
 +See [[v5:reference:logging]] for details on how to capture and redirect output.
 ===== Usage ===== ===== Usage =====
  
Line 19: Line 25:
 include 'adodb.inc.php'; include 'adodb.inc.php';
 $conn = newAdoConnection('mysqli'); $conn = newAdoConnection('mysqli');
 +
 +# Here is the earliest point where Debug Mode can be set
 +
 $conn->connect($host, $user, $pass, 'database'); $conn->connect($host, $user, $pass, 'database');
 +
 +# Enable Debug mode
 $conn->debug = true; $conn->debug = true;
 +
 $recordSet = $conn->execute('SELECT * FROM product'); $recordSet = $conn->execute('SELECT * FROM product');
 </code> </code>
Line 40: Line 52:
 This information is printed after the SQL statement, using a ''<code>'' tag. Styling can be applied using CSS, see [[#formatting|Formatting section below]]. This information is printed after the SQL statement, using a ''<code>'' tag. Styling can be applied using CSS, see [[#formatting|Formatting section below]].
  
-===== Special Options ===== +==== Possible values ==== 
-There are 3 non-boolean switches that, if set, will vary some of the output produced+ 
 +In addition to the standard ''True'' and ''False'' states accepted by this switch, there are 3 additional non-boolean values that, if set, will vary some of the output produced
 + 
 +^ Value  ^ Description                                                                                                     ^ 
 +| False  | Debug mode disabled (normal operations)                                                                         | 
 +| True   | Standard mode, prints executed SQL statements and error information including a Backtrace if the query failed. 
 +| -1     | Same as Standard mode, but with the line separators around the SQL statements suppressed.                       | 
 +| 99     | Prints a Backtrace after every query execution, **even if the execution is successful**.                        | 
 +| -99    | Debug information is only printed if query execution failed, reducing the amount of output.                     | 
 + 
 + 
 +===== Formatting ===== 
 + 
 +Starting with ADOdb 5.23.0, debug output is printed with HTML markup and styled with CSS classes. This can be leveraged to improve display of various elements.  
 +The output's structure is as follows: 
 + 
 +  * Wrapper ''div'' with //adodb-debug// class 
 +    * **SQL statement** ''div'' with //adodb-debug-sql// class 
 +      * Table with 2 columns (column 1 has ''th'' headers) 
 +        * Row 1 with the query in a ''code'' block 
 +        * Optional row 2 with the parameters in a ''code'' block, printed only there are any 
 +    * **Error message** ''div'' if query execution failed, with //adodb-debug-errmsg// class 
 +    * Code execution **backtrace** ''div'' with //adodb-debug-trace// class 
 + 
 +Here is how the output looks like with the basic stylesheet below 
 + 
 +{{ :v5:userguide:debug_output_styled.png?600 }} 
 + 
 +<code css> 
 +.adodb-debug-sql code { 
 +    font-size: large; 
 +
 +.adodb-debug-errmsg { 
 +    font-weight: bold; 
 +    color: red; 
 +
 +.adodb-debug-trace table { 
 +    border-spacing: 0; 
 +    border: 1px solid; 
 +
 +.adodb-debug-trace thead { 
 +    background-color: darkgray; 
 +
 +.adodb-debug-trace th, .adodb-debug-trace td { 
 +    border: 1px solid; 
 +    padding: 2px 6px; 
 +
 +</code> 
  
-^Value^Description^ 
-|99|If set, then the results of a debug_backtrace will be appended to every database execution, **//even if the execution is successful//**| 
-|-1|If set, and the code is being run in a browser, then the line separators around the statement are suppressed. This option has no effect when the code is run in a CLI environment.| 
-|-99|If set, then the SQL statement print is suppressed **//if the execution succeeds//**, reducing the amount of output to STDOUT | 
 ===== Limitations ===== ===== Limitations =====
  
v5/userguide/debug.1680950398.txt.gz · Last modified: 2023/04/08 12:39 by dregad