ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_abstraction:using_execute

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:userguide:learn_abstraction:using_execute [2016/03/15 01:37] – [Limiting The Number Of Returned Rows] mnewnhamv5:userguide:learn_abstraction:using_execute [2020/01/02 12:03] (current) – ↷ Links adapted because of a move operation dregad
Line 1: Line 1:
-<- v5:userguide:learn_abstraction:key_value_pairs|Key/Value Pairs ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:record_fields|Record Fields ->+<- v5:userguide:learn_abstraction:key_value_pairs|Key/Value Pairs ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:record_insertion|Inserting And Updating Records->
 ~~NOTOC~~ ~~NOTOC~~
  
Line 5: Line 5:
 The command [[v5:reference:connection:execute|execute()]] provides complete control over the reading and writing of the data in the database. The command [[v5:reference:connection:execute|execute()]] provides complete control over the reading and writing of the data in the database.
 ===== Reading Data ===== ===== Reading Data =====
-When used to read the data, the executed command returns a **Query Result**, which can be accessed and used to read the records individually.+When used to read the data, the executed command returns a **Query Result** (or RecordSet), which can be accessed and used to read the records individually.
 <code php> <code php>
 $sql = "select * from employees"; $sql = "select * from employees";
Line 27: Line 27:
               'hire_date' => '2014-01-12'               'hire_date' => '2014-01-12'
               )               )
-     * etc, until then end of file +     * etc, until the end of file 
      */      */
  
Line 43: Line 43:
 ^Command^Description| ^Command^Description|
 | [[v5:reference:recordset:move|move()]]                       | Move to the n<sup>th</sup> record of a recordset                                | | [[v5:reference:recordset:move|move()]]                       | Move to the n<sup>th</sup> record of a recordset                                |
-| [[v5:reference:connection:movenext|moveNext()]]               | Moves the cursor to the next record of the recordset from the current position  |+| [[v5:reference:recordset:movenext|moveNext()]]               | Moves the cursor to the next record of the recordset from the current position  |
 | [[v5:reference:recordset:movefirst|moveFirst()]]             | Moves the cursor to the first record of the recordset                           | | [[v5:reference:recordset:movefirst|moveFirst()]]             | Moves the cursor to the first record of the recordset                           |
-| [[v5:reference:connection:movelast|moveLast()]]               | Moves to the last record of a recordset                                         |+| [[v5:reference:recordset:movelast|moveLast()]]               | Moves to the last record of a recordset                                         |
  
 ===== Writing Data ===== ===== Writing Data =====
Line 80: Line 80:
 $result = $db->selectLimit($sql,10,200); $result = $db->selectLimit($sql,10,200);
 </code> </code>
 +
 +===== Creating A Recordset Filter =====
 +
 +A recordset filter pre-processes all the rows in a recordset after retrieval but before we use it. For example, we want to apply the PHP function //**ucwords**// to all the values in the recordset.
 +
 +In order to apply the filter, we must include the extra file **rsfilter.inc.php**
 +
 +<code php>
 +
 +include_once 'adodb/rsfilter.inc.php';
 +include_once 'adodb/adodb.inc.php';
 +
 +/*
 +* ucwords() every element in the recordset
 +*/
 +function doUcwords(&$arr,$rs)
 +{
 +     foreach($arr as $k => $v) {
 +          $arr[$k] = ucwords($v);
 +     }
 +}
 +
 +$db = newADOConnection('mysql');
 +$db->pConnect('server','user','pwd','db');
 +
 +$rs = $db->Execute('select ... from table');
 +$rs = rsFilter($rs,'doUcwords');
 +</code>
 +
 +The [[v5:reference:connection:rsfilter|rsFilter()]] method takes 2 parameters, the recordset **(passed by reference)**, and the name of the filter function. It returns the processed recordset scrolled to the first record. 
v5/userguide/learn_abstraction/using_execute.1458002245.txt.gz · Last modified: 2017/04/21 11:39 (external edit)