- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:database:text

# Plain Text

This driver is broken in ADOdb version 5 when used with PHP version 5.3 and up. This is due to the fact that the execute method has a non-compliant 3rd argument to it. Absent any user requests, this driver will be removed in ADOdb version 6.

## Description

The `text` driver allows an array of data to be processed like a read-only database table. The connect statement provides the data, as well as information about columns and names. No meta functions are supported. The *WHERE* SQL statement is ignored. In order to filter requests, An eval'd expression must be passed as a third argument.

##### Syntax

    object connect(
          array $dataArray,
          optional mixed $dataTypes=false,
          optional mixec $columnNames=false
          )

## The Connect Statement

### Parameters

#### $dataArray

This is a 2 dimensional array of data. Optionally, The first row may contain the column names. If column names are not defined in first row, they must be defined in the third argument $columnNames.

### $dataTypes

The optional parameter $dataTypes provides an array of metaTypes that match the columns in the table. This array forces a type onto each column. If the array is not provided, the driver probes each column in an attempt to discern the data types in the column. If results are ambiguous, the driver assigns a metaType of 'C'. Better results are always obtained if the column types are defined, because the driver only recognize C,I and N types.

Column names, whether provided in the first row of data or in the `$columnNames` array, must be upper case

### $columnNames

If the first row of the data array is not column names, the `$columnNames` parameter must provide a array of column names

If provided, the number of columns in the 2nd and 3rd arguments must exactly match the number in the first.

##### Syntax

    mixed execute(
          string $sql
         optional bool $ignored=false
         optional string $evalStatement=false
          )

## execute

The execute() method will return a recordset. The recordset works like a normal recordset.

There is partial support for SQL parsing. We process the SQL using the following rules:

1. SQL order by's always work for the first column ordered. Subsequent cols are ignored
2. All operations take place on the same table. In fact the FROM clause is ignored, You can use any name for the table.

1. To simplify code, all columns are returned, except when selecting 1 column

    $rs = $db->Execute('select col1,col2 from table'); // sql ignored, will generate all cols
    $rs = $db->Execute('select col1 from table');
    // sql accepted and processed -- any table name is accepted
    $rs = $db->Execute('select distinct col1 from table');
    // sql accepted and processed

Where clauses are ignored, but searching with the 3rd parameter of Execute is permitted.

Using eval may make code susceptible to SQL injection attacks

### Using an eval statement

The 3rd argument to `execute` has to use PHP syntax and the driver will attempt to eval() it. You can even use PHP functions, for example

    $rs = $db->Execute('select * from table',false,"\$COL1='abc' and \$COL2=3");

    /*
    * the 3rd param is searched -- make sure that $COL1 is a legal column name
    */

## Limitations

The following SQL operations are not supported:

- Group by, having, other clauses
- Expression columns such as min(), max()
- Joins are not permitted

## Usage

    include 'adodb/adodb.inc.php';

    $data =
    array(0=>Array(10001,'1953-09-02','Georgi','Facello','M','1986-06-26'),
          1=>Array(10002,'1964-06-02','Bezalel','Simmel','F','1985-11-21'),
          2=>Array(10003,'1959-12-03','Parto','Bamford','M','1986-08-28'),
          3=>Array(10004,'1954-05-01','Chirstian','Koblick','M','1986-12-01'),
          4=>Array(10005,'1955-01-21','Kyoichi','Maliniak', 'M','1989-09-12'),
          5=>Array(10006,'1953-04-20','Anneke','Preusig','F','1989-06-02')
    );

    $cols      = array('EMPNO','BIRTH_DATE','FIRST_NAME','LAST_NAME','HIRE_DATE');
    $metaTypes = array('I','D','C','C','C','D');

    $db = ADOnewConnection('text');

    $db->connect($data,$cols,$metaTypes);

    $sql = 'select * from table';

    $result = $db->execute($sql,"\$EMPNO=10005");

    while ($r = $result->fetchRow())
      print_r($r);

v5/database/text.txt · Last modified: 2016/01/12 17:06 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top