v5:database:text
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
database:text [2015/10/14 03:34] – mnewnham | v5:database:text [2020/01/13 13:17] (current) – fix invalid tag specification dregad | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Plain Text ====== | ====== Plain Text ====== | ||
+ | <WRAP alert> | ||
+ | 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 ===== | ===== Description ===== | ||
- | The '' | + | The '' |
------------------- | ------------------- | ||
- | <WRAP right box 300px> | + | <WRAP right box 400px> |
== Syntax == | == Syntax == | ||
object connect( | object connect( | ||
Line 14: | Line 17: | ||
==== Parameters ==== | ==== Parameters ==== | ||
=== $dataArray === | === $dataArray === | ||
- | This is a 2 dimensional array of data. Optionally, | + | This is a 2 dimensional array of data. Optionally, |
==== $dataTypes ==== | ==== $dataTypes ==== | ||
- | The optional parameter $dataTypes provides an array of [[dictionary: | + | The optional parameter $dataTypes provides an array of [[v5:dictionary: |
---------------------- | ---------------------- | ||
- | <WRAP right info 300px> | + | <WRAP right info 400px> |
- | Column names, whether provided in the first row of data or in the '' | + | Column names, whether provided in the first row of data or in the '' |
</ | </ | ||
==== $columnNames ==== | ==== $columnNames ==== | ||
- | If the first row of the data array is not column names, the '' | + | If the first row of the data array is not column names, the '' |
If provided, the number of columns in the 2< | If provided, the number of columns in the 2< | ||
- | ===== Using execute() ===== | + | ---------------------------- |
- | The execute() | + | <WRAP right box 400px> |
+ | == Syntax | ||
+ | mixed execute( | ||
+ | string $sql | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | ===== execute | ||
+ | The execute() | ||
There is partial support for SQL parsing. We process the SQL using the following rules: | There is partial support for SQL parsing. We process the SQL using the following rules: | ||
- | - SQL order by's always work for the first column ordered. Subsequent cols are ignored | + | - SQL ORDER BY's always work for the first column ordered. Subsequent cols are ignored. |
- | - All operations take place on the same table. In fact the FROM clause is ignored, | + | - All operations take place on the same table. In fact the FROM clause is ignored, |
- | - To simplify code, all columns are returned, except when selecting 1 column | + | - To simplify code, all columns are returned, except when selecting 1 column. |
- | - $rs = $db->Execute(' | + | <code php> |
- | + | $rs = $db->execute(' | |
- | + | $rs = $db->execute(' | |
- | $rs = $db->Execute(' | + | |
// sql accepted and processed -- any table name is accepted | // sql accepted and processed -- any table name is accepted | ||
- | $rs = $db->Execute(' | + | $rs = $db->execute(' |
// sql accepted and processed | // sql accepted and processed | ||
- | + | </ | |
- | | + | Where clauses are ignored, but searching with the 3rd parameter of execute() |
+ | |||
+ | ------------------------ | ||
+ | <WRAP right important 400px> | ||
+ | Using eval may make code susceptible to SQL injection attacks. | ||
+ | </ | ||
+ | ==== Using an eval statement ==== | ||
+ | The 3rd argument to '' | ||
+ | --------------------- | ||
+ | <code php> | ||
+ | // 3rd parameter is evaled PHP code, not SQL, so watch the ' | ||
+ | $rs = $db-> | ||
+ | </ | ||
- | This has to use PHP syntax and we will eval() it. You can even use PHP functions. | ||
- | $rs = $db-> | ||
- | // the 3rd param is searched -- make sure that $COL1 is a legal column name | ||
===== Limitations ===== | ===== Limitations ===== | ||
The following SQL operations are not supported: | The following SQL operations are not supported: | ||
- | * Group by, having, other clauses | + | * GROUP BY, HAVING, other clauses |
* Expression columns such as min(), max() | * Expression columns such as min(), max() | ||
* Joins are not permitted | * Joins are not permitted | ||
Line 59: | Line 80: | ||
===== Usage ===== | ===== Usage ===== | ||
<code php> | <code php> | ||
- | $db = NewADOConnection('text'); | + | include |
+ | $data = array( | ||
+ | 0=> | ||
+ | 1=> | ||
+ | 2=> | ||
+ | 3=> | ||
+ | 4=> | ||
+ | 5=> | ||
+ | ); | ||
+ | |||
+ | $cols = array(' | ||
+ | $metaTypes = array(' | ||
+ | |||
+ | $db = ADONewConnection(' | ||
+ | |||
+ | $db-> | ||
+ | |||
+ | $sql = ' | ||
+ | |||
+ | // Does not work with PHP 5.3 or later, see workaround below | ||
+ | $result = $db-> | ||
+ | |||
+ | while ($r = $result-> | ||
+ | print_r($r); | ||
+ | } | ||
</ | </ | ||
+ | |||
+ | ===== Workaround ===== | ||
+ | |||
+ | For PHP 5.3 or later, the following workaround can be used (tested with ADOdb 5.20.15). | ||
+ | |||
+ | Replace the '' | ||
+ | |||
+ | <code php> | ||
+ | $db-> | ||
+ | $result = $db-> | ||
+ | $db-> | ||
+ | </ | ||
+ | |||
+ | {{tag> |
v5/database/text.1444786483.txt.gz · Last modified: 2017/04/21 11:23 (external edit)