This is an old revision of the document!
Table of Contents
Unsupported Addons
These addon utilities are distributed as part of ADOdb, but are provided as-is, with no confirmation of compatibility with later versions of PHP or operating system, or of compatibility with a specific driver. Fixes and updates are always welcome.
Requires
tohtml.inc.php
Syntax
string rs2html ( object $recordset, optional string $tableStyles=false, optional array $columnHeaders=false, optional bool $htmlspecialchars=true, optional bool $echo = true )
rs2html
This addon provides a method of displaying a recordset in an html table. In its simplest implementation, it can be used just by passing a recordset. This is an easy way to display a retrieved recordset for debugging purposes.
Parameters
$recordset
A handle to an ADOdb recordset, provided by an execute()
or a selectLimit()
statement.
$tableStyles
Historically this parameter was used for items like 'border' and 'width' but can also be used for modern attributes such as 'class' and 'style'. Double quotes in the statement should be escaped.
$columnHeaders
If provided, the numeric array is used for column headers instead of the field names. It must contain index entries for all columns.
$htmlSpecialChars
By default, the PHP function htmlSpecialChars is applied to all values. This parameter disables this functionality.
$echo
By default, the output is echoed directly to the screen. If the value is set to false, the output is collected in a string and returned from the function.
Global Variables
THe following variables may be defined, and are globalized into the function
Variable | Description |
---|---|
$gSQLMaxRows | The maximum number of rows displayed in the table. This does not affect the number of rows retrieved |
$gSQLBlockRows | The records returned are grouped into blocks of this number of records. Historically, this feature was used to improve rendering speed. |
$ADODB_ROUND | The number of decimal places that floating point numbers are rounded to |
Usage
/* * Connection to Access northwind database */ include 'adodb/adodb.inc.php'; include 'adodb/tohtml.inc.php'; $db = newAdoConnection('access'); $sql = 'select * from orders' $recordset = $db->execute($sql); $tableStyles = "class=\"rs2class\" style='border:1px dashed silver'"; rs2html($recordset,$tableStyles);
rs2csv & rs2tab
Requires
toexport.inc.php
Syntax
string rs2csv( obj $recordSet optional bool $addTitles=true ) string rs2tab( obj $recordSet optional bool $addTitles=true )
Description
The function rs2csv()
takes a recordset object as an argument and returns the data as a string containing a CSV format file. If selected, the first row contains the column names. The rs2tab function returns the data as tab separated data
Usage
/* * Connection to Northwind Database */ $sql = "SELECT * FROM orders"; $recordset = $db->execute($sql); $csv = rs2csv($recordset);
String fields are not quoted or escaped per standard CSV format
rs2csvfile & rs2tabfile
Requires
toexport.inc.php
Syntax
void rs2csvfile( obj $recordSet handle $filePointer optional bool $addTitles=true ) void rs2tabfile( obj $recordSet handle $filePointer optional bool $addTitles=true )
Description
The function rs2csvfile()
takes a recordset object as an argument and outputs the data to a CSV file indicated by the file pointer $filePointer . If selected, the first row contains the column names. The rs2tabfile()
function returns the data as tab-separated.
Usage
/* * Connection to Northwind Database */ $filePointer = fopen('/tmp/products.csv','w'); $sql = "SELECT * FROM products"; $recordset = $db->execute($sql); $csv = rs2csv($recordset, $filePointer);
String fields are not quoted or escaped per standard CSV format
rs2csvout & rs2tabout
Requires
toexport.inc.php
Syntax
string rs2csvout( obj $recordSet optional bool $addTitles=true ) string rs2tabout( obj $recordSet optional bool $addTitles=true )
Description
The function rs2csvout()
takes a recordset object as an argument and sends the data as a string containing a CSV format file to the PHP STDOUT. If selected, the first row contains the column names. The function rs2tabout()
. Returns the data in tab-separated format.
Usage
/* * Connection to Northwind Database */ $sql = "SELECT * FROM products"; $recordset = $db->execute($sql); $csv = rs2tabout($recordset);
String fields are not quoted or escaped per standard CSV format
The xmlrpc library
This addon provides an interface between the adodb recordset and the php xmlrpc library. More Information
Requires
adodb-pager.inc.php
Paging & Scrolling with ADOdb Pager
The following code creates a very simple recordset pager, where you can scroll from page to page of a recordset.
include_once 'adodb/adodb.inc.php'; include_once 'adodb/adodb-pager.inc.php'; session_start(); $db = newADOConnection('mysql'); $db->connect('localhost','root','','xphplens'); $sql = "select * from adoxyz "; $pager = new ADODB_Pager($db,$sql); $pager->render($rows_per_page=5);
This will create a basic record pager that looks like this:
|< << >> >| ^ID^First Name^Last Name^Date Created^ |36|Alan|Turing|Sat 06, Oct 2001| |37|Serena|Williams|Sat 06, Oct 2001| |38|Yat Sun|Sun|Sat 06, Oct 2001| |39|Wai Hun|See|Sat 06, Oct 2001| |40|Steven|Oey|Sat 06, Oct 2001|
Page 8/10
The number of rows to display at one time is controled by the Render($rows) method. If you do not pass any value to Render(), ADODB_Pager will default to 10 records per page.
You can control the column titles by modifying your SQL (supported by most databases):
$sql = 'select id as "ID", firstname as "First Name", lastname as "Last Name", created as "Date Created" from adoxyz';
The above code can be found in the adodb/tests/testpaging.php example included with this release, and the class ADODB_Pager in adodb/adodb-pager.inc.php.
The ADODB_Pager code can be adapted by a programmer so that the text links can be replaced by images, and the dull white background be replaced with more interesting colors.
You can also allow display of html by setting
$pager->htmlSpecialChars = false.
Some of the code used here was contributed by Iván Oliva and Cornel G..