"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/tests/test-active-record.php Source File", "datetime" => "Sat Dec 2 19:22:26 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

test-active-record.php

00001 <?php
00002 
00003         include_once('../adodb.inc.php');
00004         include_once('../adodb-active-record.inc.php');
00005         
00006         // uncomment the following if you want to test exceptions
00007         if (@$_GET['except']) {
00008                 if (PHP_VERSION >= 5) {
00009                         include('../adodb-exceptions.inc.php');
00010                         echo "<h3>Exceptions included</h3>";
00011                 }
00012         }
00013 
00014         $db = NewADOConnection('mysql://root@localhost/northwind');
00015         $db->debug=1;
00016         ADOdb_Active_Record::SetDatabaseAdapter($db);
00017 
00018         $db->Execute("CREATE TEMPORARY TABLE `persons` (
00019                         `id` int(10) unsigned NOT NULL auto_increment,
00020                         `name_first` varchar(100) NOT NULL default '',
00021                         `name_last` varchar(100) NOT NULL default '',
00022                         `favorite_color` varchar(100) NOT NULL default '',
00023                         PRIMARY KEY  (`id`)
00024                     ) ENGINE=MyISAM;
00025                    ");
00026                            
00027         class Person extends ADOdb_Active_Record{}
00028         $person = new Person();
00029         
00030         echo "<p>Output of getAttributeNames: ";
00031         var_dump($person->getAttributeNames());
00032         
00047         $person = new Person();
00048         $person->nameFirst = 'Andi';
00049         $person->nameLast  = 'Gutmans';
00050         $person->save(); // this save() will fail on INSERT as favorite_color is a must fill...
00051         
00052         
00053         $person = new Person();
00054         $person->name_first     = 'Andi';
00055         $person->name_last      = 'Gutmans';
00056         $person->favorite_color = 'blue';
00057         $person->save(); // this save will perform an INSERT successfully
00058         
00059         echo "<p>The Insert ID generated:"; print_r($person->id);
00060         
00061         $person->favorite_color = 'red';
00062         $person->save(); // this save() will perform an UPDATE
00063         
00064         $person = new Person();
00065         $person->name_first     = 'John';
00066         $person->name_last      = 'Lim';
00067         $person->favorite_color = 'lavender';
00068         $person->save(); // this save will perform an INSERT successfully
00069         
00070         // load record where id=2 into a new ADOdb_Active_Record
00071         $person2 = new Person();
00072         $person2->Load('id=2');
00073         
00074         var_dump($person2);
00075         
00076         $activeArr = $db->GetActiveRecordsClass($class = "Person",$table = "persons","id=".$db->Param(0),array(2));
00077         $person2 =& $activeArr[0];
00078         echo "<p>Name (should be John): ",$person->name_first, " <br> Class (should be Person): ",get_class($person2);  
00079         
00080 
00081 
00082 ?>