This is an old revision of the document!
Table of Contents
Logging
ADOdb provides an internal debugging system that exposes the SQL commands used to execute a command, as well as other messages that can provide guidance when, for example, trying to establish a connection to the database. The earliest that debugging can be started is after instantiating the driver but before connection. In its simplest usage, debugging is enabled as follows:
include '/adodb-dir/adodb.inc.php'; $db = newAdoConnection('mysqli'); /* * Initialize debugging */ $db->debug = true; $db->connect('host','user','pass','database');
This might produce output something like:
-----<hr> (mysqli): select * from usersx -----<hr> Query: select * from usersx failed. Table 'db.usersx' doesn't exist 1146: Table 'db.usersx' doesn't exist ADOConnection._Execute(select * from usersx, false)% line 1313, file: C:\dev\GitHub\ADOdb\adodb.inc.php ADOConnection.Execute(select * from usersx)% line 46, file: C:\dev\tests\test7.php
The output is suitable for viewing in a browser, with messages from the database driver as well as backtrace data if there are problems. Note that debugging can be switched on and off during code execution as required.
Alternative Debugging Levels
The following alternative levels are available. Each produces a slightly different output.
Debug Level | Description |
---|---|
true | Default as described above |
-1 | The most minimal logging level. Formatted as the default option, but does not include backtrace data or any ADOdb debugging/logging messages |
-99 | Adds ADOdb messages to the above format, but no backtrace data |
99 | The logging equivalent of true |
2 | Use the datalogging object as described below |
Overriding The Default Logging Function
The default logging behavior is to send all messages to STDOUT, but the behavior may be modified by either:
- Defining a constant ADODB_OUTP which holds the name of the function that overrides the standard value
- A variable $ADODB_OUTP which is globalized and achieves the same as above. This function can be dynamically changed.
Function Definition
The overriding function must accept 2 arguments:
- A String which contains the message
- A boolean which indicates whether to throw a newline. This may be discarded based on how the function works
Example Function
DEFINE ('ADODB_OUTP','myLogger'); function myLogger($msg,$discard) { print "\nThis is my messsage: $msg"; }