v5:database:text
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
database:text [2015/10/08 04:00] – created mnewnham | v5:database:text [2018/07/01 22:45] – prefer functions start lowercase (#430) peterdd | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Plain Text ====== | ====== Plain Text ====== | ||
- | The '' | + | <WRAP alert> |
+ | This driver | ||
+ | </ | ||
===== Description ===== | ===== Description ===== | ||
- | $db = NewADOConnection(' | + | The '' |
- | $db->Connect($array,[$types],[$colnames]); | + | ------------------- |
- | Parameter | + | <WRAP right box 400px> |
- | column names. If column names is not defined in first row, you MUST define $colnames, | + | == Syntax == |
- | the 3rd parameter. | + | object connect( |
- | Parameter | + | |
- | the number | + | optional mixed $dataTypes=false, |
- | by MetaType: (B,C,I,L,N). If undefined, we will probe for $this-> | + | optional mixec $columnNames=false |
- | to guess the type. Only C,I and N are recognised. | + | |
- | Parameter $colnames is optional. If defined, it is an array that contains the | + | </ |
- | column | + | ===== The Connect Statement ==== |
- | column names. | + | ==== Parameters ==== |
- | | + | === $dataArray === |
- | We have partial support for SQL parsing. We process the SQL using the following rules: | + | This is a 2 dimensional array of data. Optionally, |
- | 1. SQL order by's always work for the first column ordered. Subsequent cols are ignored | + | ==== $dataTypes ==== |
- | 2. All operations take place on the same table. No joins possible. In fact the FROM clause | + | The optional |
- | is ignored! You can use any name for the table. | + | ---------------------- |
- | 3. To simplify code, all columns are returned, except when selecting 1 column | + | <WRAP right info 400px> |
- | $rs = $db->Execute(' | + | Column |
- | We special case handling of 1 column because it is used in filter popups | + | </ |
- | $rs = $db->Execute(' | + | |
- | // sql accepted and processed -- any table name is accepted | + | |
- | $rs = $db->Execute(' | + | ==== $columnNames ==== |
- | // sql accepted and processed | + | If the first row of the data array is not column names, |
- | 4. Where clauses are ignored, but searching with the 3rd parameter of Execute is permitted. | + | |
- | This has to use PHP syntax and we will eval() it. You can even use PHP functions. | + | If provided, the number of columns in the 2< |
- | $rs = $db->Execute(' | + | |
- | // the 3rd param is searched -- make sure that $COL1 is a legal column name | + | ---------------------------- |
- | // and all column names must be in upper case. | + | <WRAP right box 400px> |
- | 4. Group by, having, other clauses | + | == Syntax == |
- | 5. Expression columns, min(), max() are ignored | + | mixed execute( |
- | 6. All data is readonly. Only SELECTs permitted. | + | string $sql |
+ | | ||
+ | | ||
+ | ) | ||
+ | </ | ||
+ | ===== execute ===== | ||
+ | The execute() method | ||
+ | |||
+ | There is partial support for SQL parsing. We process the SQL using the following rules: | ||
+ | | ||
+ | | ||
+ | |||
+ | - To simplify code, all columns are returned, except when selecting 1 column | ||
+ | |||
+ | <code php> | ||
+ | $rs = $db->execute(' | ||
+ | $rs = $db->execute(' | ||
+ | // sql accepted and processed -- any table name is accepted | ||
+ | $rs = $db->execute(' | ||
+ | // sql accepted and processed | ||
+ | </ | ||
+ | Where clauses are ignored, but searching with the 3rd parameter of Execute is permitted. | ||
+ | |||
+ | ------------------------ | ||
+ | <WRAP right important 400px> | ||
+ | Using eval may make code susceptible to SQL injection attacks | ||
+ | </ | ||
+ | ==== Using an eval statement ==== | ||
+ | The 3rd argument to '' | ||
+ | --------------------- | ||
+ | <code php> | ||
+ | $rs = $db->execute(' | ||
+ | |||
+ | /* | ||
+ | * the 3rd param is searched -- make sure that $COL1 is a legal column name | ||
+ | */ | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | ===== Limitations ===== | ||
+ | The following SQL operations are not supported: | ||
+ | * Group by, having, other clauses | ||
+ | | ||
+ | * Joins are not permitted | ||
+ | |||
+ | ===== Usage ===== | ||
+ | <code php> | ||
+ | include ' | ||
+ | |||
+ | $data = | ||
+ | array(0=> | ||
+ | 1=> | ||
+ | 2=> | ||
+ | 3=> | ||
+ | 4=> | ||
+ | 5=> | ||
+ | ); | ||
+ | |||
+ | $cols = array(' | ||
+ | $metaTypes = array(' | ||
+ | |||
+ | $db = ADOnewConnection(' | ||
+ | |||
+ | |||
+ | $db-> | ||
+ | |||
+ | $sql = ' | ||
+ | |||
+ | $result = $db-> | ||
+ | |||
+ | while ($r = $result-> | ||
+ | print_r($r); | ||
+ | |||
+ | </ |
v5/database/text.txt · Last modified: 2020/01/13 13:17 by dregad