- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:activerecord:code_snippet_2

## ActiveRecord Code Sample

    /*
    * Include the previously defined code snippet
    */

    class person extends ADOdb_Active_Record{}
    $person = new person();

    echo "<p>Output of getAttributeNames: ";
    var_dump($person->getAttributeNames());

    /**
     * Outputs the following:
     * array(4) {
     *    [0]=>
     *    string(2) "id"
     *    [1]=>
     *    string(9) "name_first"
     *    [2]=>
     *    string(8) "name_last"
     *    [3]=>
     *    string(13) "favorite_color"
     *  }
     */

    $person = new person();
    $person->name_first = 'Andi';
    $person->name_last  = 'Gutmans';
    $person->save(); // this save() will fail on INSERT as favorite_color is a must fill...

    $person = new person();
    $person->name_first     = 'Andi';
    $person->name_last      = 'Gutmans';
    $person->favorite_color = 'blue';
    $person->save(); // this save will perform an INSERT successfully

    echo "<p>The Insert ID generated:"; print_r($person->id);

    $person->favorite_color = 'red';
    $person->save(); // this save() will perform an UPDATE

    $person = new person();
    $person->name_first     = 'John';
    $person->name_last      = 'Lim';
    $person->favorite_color = 'lavender';
    $person->save(); // this save will perform an INSERT successfully

    /*
    *  load record where id=2 into a new ADOdb_Active_Record
    */

    $person2 = new person();
    $person2->Load('id=2');
    var_dump($person2);

    /*
    * retrieve an array of records
    */
    $activeArr = $db->GetActiveRecordsClass(
                      $class = "person",
                      $table = "persons",
                      "id=".$db->Param(0),
                      array(2));

    $person2 = $activeArr[0];
    echo "<p>Name first (should be John): ",$person->name_first, "<br>Class = ",get_class($person2);

v5/activerecord/code_snippet_2.txt · Last modified: 2016/01/12 17:15 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top