v5:userguide:learn_fields:start_lesson
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| v5:userguide:learn_fields:start_lesson [2016/03/17 04:22] – mnewnham | v5:userguide:learn_fields:start_lesson [2016/03/18 00:32] (current) – mnewnham | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <- v5: | + | <- v5: |
| ~~NOTOC~~ | ~~NOTOC~~ | ||
| ====== Fields And Fields Objects ====== | ====== Fields And Fields Objects ====== | ||
| Line 5: | Line 5: | ||
| ADOdb provides a number of methods for controlling returned data. The data may be represented as arrays, both numeric and associative, | ADOdb provides a number of methods for controlling returned data. The data may be represented as arrays, both numeric and associative, | ||
| + | ===== $ADODB_FETCH_MODE ===== | ||
| + | The global variable [[v5: | ||
| + | ^Name^Value^Description^ | ||
| + | |ADODB_FETCH_DEFAULT|0|The recordset is returned in the default provided by the PHP driver. Use of this value is not recommended if writing cross-database applications| | ||
| + | |ADODB_FETCH_NUM|1|The recordset is returned as a numeric array| | ||
| + | |ADODB_FETCH_ASSOC|2|The recordset is returned as an associative array| | ||
| + | |ADODB_FETCH_BOTH|3|The record is returned as both a numeric and associative arrays. Not supported in some databases| | ||
| - | In addition to returning recordsets on a row by row basis, ADOdb allows the user to interrogate each row on a field by field basis. | + | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| + | returns: | ||
| + | array([0] =>' | ||
| + | [1] =>' | ||
| + | [2] =>' | ||
| + | etc.... | ||
| + | ) | ||
| - | <code php> | + | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
| - | /* | + | returns: |
| - | * Load the common code | + | |
| - | */ | + | |
| - | include | + | ['col2'] => ' |
| + | etc..... | ||
| + | ) | ||
| - | may | + | $ADODB_FETCH_MODE = ADODB_FETCH_BOTH; |
| - | while (!$recordSet->EOF) { | + | returns: |
| + | array([0] = ' | ||
| + | [' | ||
| + | [1] = ' | ||
| + | [' | ||
| + | [2] => ' | ||
| + | [' | ||
| + | etc..... | ||
| + | ) | ||
| + | |||
| - | $fld = $recordSet-> | ||
| - | $type = $recordSet-> | ||
| - | |||
| - | if ( $type == ' | ||
| - | print $recordSet-> | ||
| - | | ||
| - | . $recordSet-> | ||
| - | | ||
| - | | ||
| - | print $recordSet-> | ||
| - | |||
| - | | ||
| - | |||
| - | } | ||
| - | $recordSet-> | ||
| - | $conn-> | ||
| - | </ | ||
| - | |||
| - | In this example, we check the field type of the second column using [[v5: | ||
| - | |||
| - | name: name of column | ||
| - | type: native field type of column | ||
| - | max_length: maximum length of field. | ||
| - | | ||
| - | Some databases such as MySQL do not return the maximum length of the field correctly. In these cases max_length will be set to -1. | ||
| - | We then use [[v5: | ||
| - | |||
| - | C: character fields that should be shown in a <input type=" | ||
| - | X: TeXt, large text fields that should be shown in a < | ||
| - | B: Blobs, or Binary Large Objects. Typically images. | ||
| - | D: Date field | ||
| - | T: Timestamp field | ||
| - | L: Logical field (boolean or bit-field) | ||
| - | I: Integer field | ||
| - | N: Numeric field. Includes autoincrement, | ||
| - | | ||
| - | R: Serial field. Includes serial, autoincrement integers. | ||
| - | This works for selected databases. | ||
| - | | ||
| - | If the metatype is of type date or timestamp, then we print it using the user defined date format with [[v5: | ||
| - | |||
| - | Another use for '' | ||
| - | |||
| - | ====== Usage ===== | ||
| - | <code php> | ||
| - | /* | ||
| - | * DB Connection assumed | ||
| - | */ | ||
| - | $result = $db-> | ||
| - | $r = $result-> | ||
| - | print $r-> | ||
| - | /* | ||
| - | * Returns: 10 | ||
| - | */ | ||
| - | </ | ||
v5/userguide/learn_fields/start_lesson.1458184932.txt.gz · Last modified: (external edit)
