v5:database:text
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v5:database:text [2016/01/13 01:53] – ↷ Page moved from database:text to v5:database:text mnewnham | v5:database:text [2020/01/13 13:17] (current) – fix invalid tag specification dregad | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| </ | </ | ||
| ===== Description ===== | ===== Description ===== | ||
| - | The '' | + | The '' |
| ------------------- | ------------------- | ||
| <WRAP right box 400px> | <WRAP right box 400px> | ||
| Line 17: | 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 400px> | <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< | ||
| Line 44: | Line 44: | ||
| 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. |
| <code php> | <code php> | ||
| - | $rs = $db->Execute(' | + | $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 | + | Where clauses are ignored, but searching with the 3rd parameter of execute() |
| ------------------------ | ------------------------ | ||
| <WRAP right important 400px> | <WRAP right important 400px> | ||
| - | Using eval may make code susceptible to SQL injection attacks | + | Using eval may make code susceptible to SQL injection attacks. |
| </ | </ | ||
| ==== Using an eval statement ==== | ==== Using an eval statement ==== | ||
| - | The 3rd argument to '' | + | The 3rd argument to '' |
| --------------------- | --------------------- | ||
| <code php> | <code php> | ||
| - | $rs = $db->Execute(' | + | // 3rd parameter is evaled PHP code, not SQL, so watch the ' |
| - | + | $rs = $db->execute(' | |
| - | /* | + | |
| - | * the 3rd param is searched -- make sure that $COL1 is a legal column name | + | |
| - | */ | + | |
| </ | </ | ||
| Line 77: | Line 74: | ||
| ===== 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 85: | Line 82: | ||
| include ' | include ' | ||
| - | $data = | + | $data = array( |
| - | array(0=> | + | |
| - | 1=>Array(10002,' | + | 1=>array(10002,' |
| - | 2=>Array(10003,' | + | 2=>array(10003,' |
| - | 3=>Array(10004,' | + | 3=>array(10004,' |
| - | 4=>Array(10005,' | + | 4=>array(10005,' |
| - | 5=>Array(10006,' | + | 5=>array(10006,' |
| ); | ); | ||
| - | $cols = array(' | + | $cols = array(' |
| $metaTypes = array(' | $metaTypes = array(' | ||
| - | $db = ADOnewConnection(' | + | $db = ADONewConnection(' |
| - | + | $db-> | |
| - | $db-> | + | |
| $sql = ' | $sql = ' | ||
| - | $result = $db-> | + | // Does not work with PHP 5.3 or later, see workaround below |
| + | $result = $db-> | ||
| - | while ($r = $result-> | + | while ($r = $result-> |
| print_r($r); | 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.1452646423.txt.gz · Last modified: (external edit)
