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
reference:debug [2015/11/29 01:49] – [Description] dregadv5:userguide:debug [2024/01/09 11:20] (current) – [Description] link to Logging page dregad
Line 4: Line 4:
 <WRAP right box> <WRAP right box>
 == Syntax == == Syntax ==
-  $connection->debug = boolean;+  $connection->debug = boolean|int;
 </WRAP> </WRAP>
  
 ===== 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 =====
-The debug option can be enabled and disabled at any time, to debug portions of a program. The earliest it can be enabled is after the inclusion of the driver, and before the connection. In the following example, the table name is spelled incorrectly (it should be **products**). When run without debugging, the execution of the statement simply returns false.+ 
 +The //debug// option can be enabled and disabled at any time, to debug portions of a program.  
 +The earliest it can be set is after the inclusion of the driver, and before the connection.  
 + 
 +In the following example, the table name is spelled incorrectly (it should be **products**). When run without debugging, the execution of the statement produces no output and simply returns false.
    
 <code php> <code php>
-include '/dev/access/adodb-master/adodb.inc.php'; +include 'adodb.inc.php'; 
-$conn = newAdoConnection('access'); +$conn = newAdoConnection('mysqli'); 
-$conn->connect('northwind');+ 
 +# Here is the earliest point where Debug Mode can be set 
 + 
 +$conn->connect($host, $user, $pass, 'database'); 
 + 
 +# Enable Debug mode
 $conn->debug = true; $conn->debug = true;
-/* + 
-* Invalid syntax in select statment +$recordSet = $conn->execute('SELECT FROM product');
-*/ +
-$recordSet = $conn->Execute('select from product');+
 </code> </code>
 +
 The information returned on STDOUT is: The information returned on STDOUT is:
 <code> <code>
------<hr> +------------------------------------------------------------------------------ 
-(access)select from product  +mysqliSELECT FROM product 
-    +------------------------------------------------------------------------------ 
------<hr>+Query: select * from product failed. Table 'database.product' doesn't exist 
 +1146: Table 'database.product' doesn't exist
  
-Warning: odbc_exec(): SQL error[Microsoft][ODBC Microsoft Access Driver] The Microsoft Access  +Call stack (most recent call first): 
-database engine cannot find the input table or query 'product'Make sure it exists and that its + 2. ADOConnection::_Execute(SELECT * FROM product) in .../drivers/adodb-mysqli.inc.php line 1091 
-name is spelled correctly., SQL state S0002 in SQLExecDirect in /ADOdb/drivers/adodb-odbc.inc.php  + 1. ADODB_mysqli::execute(SELECT FROM product) in .../test.php line 36
-on line 540 +
-S0002[Microsoft][ODBC Microsoft Access Driver] The Microsoft Access database engine cannot  +
-find the input table or query 'product'. Make sure it exists and that its name is spelled correctly. +
-ADOConnection._Execute(select from product, false)% line 1163, file: C:\dev\access\ADOdb-master\adodb.inc.php +
-ADOConnection.Execute(select * from product)% line    6, file: C:\temp\access\test3.php+
 </code>  </code> 
-  + 
-Information on STDERR +By default, the parameters passed to the query are compressed into a set of //key => value// pairs.  
-<code> +This information is printed after the SQL statement, using a ''<code>'' tag. Styling can be applied using CSS, see [[#formatting|Formatting section below]]. 
-PHP Warning:  odbc_exec()SQL error: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Access + 
-database engine cannot find the input table or query 'product'Make sure it exists and that its  +==== Possible values ==== 
-name is spelled correctly., SQL state S0002 in SQLExecDirect in C:\ADOdb\drivers\adodb-odbc.inc.php on line 540+ 
 +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.0debug 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> </code>
 +
 +
 ===== Limitations ===== ===== Limitations =====
  
v5/userguide/debug.1448758153.txt.gz · Last modified: 2017/04/21 11:39 (external edit)