- Timestamp:
- 09/26/13 15:41:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/tests/test-active-record.php
r34 r8222 12 12 } 13 13 14 $db = NewADOConnection('mysql://root@localhost/northwind ');14 $db = NewADOConnection('mysql://root@localhost/northwind?persist'); 15 15 $db->debug=1; 16 16 ADOdb_Active_Record::SetDatabaseAdapter($db); 17 17 18 18 19 $db->Execute("CREATE TEMPORARY TABLE `persons` ( 19 20 `id` int(10) unsigned NOT NULL auto_increment, … … 25 26 "); 26 27 27 class Person extends ADOdb_Active_Record{} 28 $db->Execute("CREATE TEMPORARY TABLE `children` ( 29 `id` int(10) unsigned NOT NULL auto_increment, 30 `person_id` int(10) unsigned NOT NULL, 31 `name_first` varchar(100) NOT NULL default '', 32 `name_last` varchar(100) NOT NULL default '', 33 `favorite_pet` varchar(100) NOT NULL default '', 34 PRIMARY KEY (`id`) 35 ) ENGINE=MyISAM; 36 "); 37 38 class Person extends ADOdb_Active_Record{ function ret($v) {return $v;} } 28 39 $person = new Person(); 40 ADOdb_Active_Record::$_quoteNames = '111'; 29 41 30 42 echo "<p>Output of getAttributeNames: "; … … 72 84 $person2->Load('id=2'); 73 85 74 var_dump($person2); 86 $activeArr = $db->GetActiveRecordsClass($class = "Person",$table = "Persons","id=".$db->Param(0),array(2)); 87 $person2 = $activeArr[0]; 88 echo "<p>Name (should be John): ",$person->name_first, " <br> Class (should be Person): ",get_class($person2),"<br>"; 75 89 76 $ activeArr = $db->GetActiveRecordsClass($class = "Person",$table = "persons","id=".$db->Param(0),array(2));77 $ person2 =& $activeArr[0];78 echo "<p>Name (should be John): ",$person->name_first, " <br> Class (should be Person): ",get_class($person2);90 $db->Execute("insert into children (person_id,name_first,name_last) values (2,'Jill','Lim')"); 91 $db->Execute("insert into children (person_id,name_first,name_last) values (2,'Joan','Lim')"); 92 $db->Execute("insert into children (person_id,name_first,name_last) values (2,'JAMIE','Lim')"); 79 93 94 $newperson2 = new Person(); 95 $person2->HasMany('children','person_id'); 96 $person2->Load('id=2'); 97 $person2->name_last='green'; 98 $c = $person2->children; 99 $person2->save(); 80 100 101 if (is_array($c) && sizeof($c) == 3 && $c[0]->name_first=='Jill' && $c[1]->name_first=='Joan' 102 && $c[2]->name_first == 'JAMIE') echo "OK Loaded HasMany</br>"; 103 else { 104 var_dump($c); 105 echo "error loading hasMany should have 3 array elements Jill Joan Jamie<br>"; 106 } 107 108 class Child extends ADOdb_Active_Record{}; 109 $ch = new Child('children',array('id')); 110 $ch->BelongsTo('person','person_id','id'); 111 $ch->Load('id=1'); 112 if ($ch->name_first !== 'Jill') echo "error in Loading Child<br>"; 113 114 $p = $ch->person; 115 if ($p->name_first != 'John') echo "Error loading belongsTo<br>"; 116 else echo "OK loading BelongTo<br>"; 81 117 118 $p->hasMany('children','person_id'); 119 $p->LoadRelations('children', " Name_first like 'J%' order by id",1,2); 120 if (sizeof($p->children) == 2 && $p->children[1]->name_first == 'JAMIE') echo "OK LoadRelations<br>"; 121 else echo "error LoadRelations<br>"; 122 123 $db->Execute("CREATE TEMPORARY TABLE `persons2` ( 124 `id` int(10) unsigned NOT NULL auto_increment, 125 `name_first` varchar(100) NOT NULL default '', 126 `name_last` varchar(100) NOT NULL default '', 127 `favorite_color` varchar(100) default '', 128 PRIMARY KEY (`id`) 129 ) ENGINE=MyISAM; 130 "); 131 132 $p = new adodb_active_record('persons2'); 133 $p->name_first = 'James'; 134 135 $p->name_last = 'James'; 136 137 $p->HasMany('children','person_id'); 138 $p->children; 139 var_dump($p); 140 $p->Save(); 82 141 ?>
Note: See TracChangeset
for help on using the changeset viewer.