ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_fields:field_objects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
v5:userguide:learn_fields:field_objects [2016/03/18 02:13] – created mnewnhamv5:userguide:learn_fields:field_objects [2021/03/09 09:38] (current) – [Interrogating The Columns] wrong variable name in code sample dregad
Line 2: Line 2:
 ~~NOTOC~~ ~~NOTOC~~
 ====== Fields As Objects ====== ====== Fields As Objects ======
-In Lesson 2, the concept of the **//ActualTypes//** was explained. In this section, we show how the value of field, and also the attributes of the same field can be obtained. By treating the returned result set as a 2 dimensional array, we can process each row on a column-by-column basis.+In Lesson 2, the concept of the **//ActualTypes//** was explained.  
 +In this section, we show how the value of field, as well as its attributescan be obtained.  
 +By treating the returned result set as a 2 dimensional array, we can process each row on a column-by-column basis.
  
 ===== The Limits Of The Array ===== ===== The Limits Of The Array =====
Line 13: Line 15:
  
 ===== Walking The Rows Of A ResultSet ===== ===== Walking The Rows Of A ResultSet =====
-In Lesson 1, we saw a number of ways of moving from one row to the next. It is important to not mix methods, as some methods read the record and automatically advance the record pointer, and some do not. However in all cases, a flag **EOF** is set as soon as the end of the result set is reached. In the following example, the method [[v5:reference:connection:movenext|moveNext()]] is used.+In Lesson 1, we saw a number of ways of moving from one row to the next. It is important to not mix methods, as some methods read the record and automatically advance the record pointer, and some do not. However in all cases, a flag **EOF** is set as soon as the end of the result set is reached. In the following example, the method [[v5:reference:recordset:movenext|moveNext()]] is used.
    
 Note the for both rows and columns, ADOdb uses the PHP convention of a Zero-Based (0) array, as opposed to SQL offsets, which are One-based (1). Note the for both rows and columns, ADOdb uses the PHP convention of a Zero-Based (0) array, as opposed to SQL offsets, which are One-based (1).
Line 35: Line 37:
  
 </code> </code>
 +===== Interrogating The Columns =====
 We are now going to loop through each column of each row and use 3 methods to ascertain the value and attributes of the field: We are now going to loop through each column of each row and use 3 methods to ascertain the value and attributes of the field:
   * [[v5:reference:recordset:fields|fields()]], which returns the value of a field at a specified offset.   * [[v5:reference:recordset:fields|fields()]], which returns the value of a field at a specified offset.
Line 48: Line 51:
          */           */ 
          $fieldInfo = $recordSet->fetchField($colIndex);          $fieldInfo = $recordSet->fetchField($colIndex);
-         $type      = $recordSet->metaType($fld->type);+         $type      = $recordSet->metaType($fieldInfo->type);
            
          /*          /*
          * This is the value of the field          * This is the value of the field
          */          */
-         $value     = $recordSet->fields[$colIndex];+         $value     = $recordSet->fields($colIndex);
                        
 </code> </code>
 +===== MetaType Based Decisions =====
 At this point in the loop, we make a formatting decision based on the portable metaType attribute of the column. If the type of the field is a timestamp, we will immediately format the data to present the data as a human readable date At this point in the loop, we make a formatting decision based on the portable metaType attribute of the column. If the type of the field is a timestamp, we will immediately format the data to present the data as a human readable date
 <code php>          <code php>         
Line 69: Line 73:
      * End of the colums, move to next row      * End of the colums, move to next row
      */       */ 
-     $recordSet->MoveNext();+     $recordSet->moveNext();
  
 } }
 </code> </code>
 <WRAP info center 300px> <WRAP info center 300px>
-**End Of Lesson 3**+**End Of Lesson**
 </WRAP> </WRAP>
  
  
v5/userguide/learn_fields/field_objects.1458263606.txt.gz · Last modified: 2017/04/21 11:40 (external edit)