ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:dictionary:structure:sample_usage

Differences

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

Link to this comparison view

Next revision
Previous revision
v5:dictionary:structure:complex_sample [2016/04/09 21:36] – created mnewnhamv5:dictionary:structure:sample_usage [2016/04/09 21:46] (current) mnewnham
Line 1: Line 1:
 ====== Sample Usage ====== ====== Sample Usage ======
 +This page shows the usage of the metaObjectStructure in various situations.
 +------------------------------------
 ===== Complex Example ===== ===== Complex Example =====
-he following complex example shows the additional functionality of updating indexes, as well as chaining methods+The following complex example shows the additional functionality of updating indexes, as well as chaining methods
 <code php> <code php>
 $dict = NewDataDictionary($db); $dict = NewDataDictionary($db);
Line 8: Line 10:
 $t->addAttribute('ENGINE INNODB','mysql'); $t->addAttribute('ENGINE INNODB','mysql');
 $t->addColumnObject('COL1','I'); $t->addColumnObject('COL1','I');
-$t->addColumnObject('COL1','I')->addAttribute('NOTNULL');+$t->addColumnObject('COL1','I') 
 +                   ->addAttribute('NOTNULL');
  
 $c = $t->addColumnObject('COL2','C(64)'); $c = $t->addColumnObject('COL2','C(64)');
Line 16: Line 19:
 $ii = $i->addIndexItemObject('COL1'); $ii = $i->addIndexItemObject('COL1');
  
-$t->addColumnObject('COL1','C(32)')->addAttribute('NOTNULL')->addAttribute(array('DEFAULT'=>'abc'));+$t->addColumnObject('COL1','C(32)') 
 +                ->addAttribute('NOTNULL') 
 +                ->addAttribute(array('DEFAULT'=>'abc'));
  
-$t->addColumnObject('COL2','I')->addAttribute('NOTNULL')->addAttribute('PRIMARY')->addAttribute('AUTO');+$t->addColumnObject('COL2','I') 
 +               ->addAttribute('NOTNULL') 
 +               ->addAttribute('PRIMARY') 
 +               ->addAttribute('AUTO');
 $t->addColumnObject('COL3','N(12.2)'); $t->addColumnObject('COL3','N(12.2)');
-$t->addColumnObject('COL4','C(64)')->addAttribute(array('CHARACTER SET'=>'"ascii"'))->addAttribute(array('COLLATE'=>'"latin1_swedish_ci"'),'mysql');+$t->addColumnObject('COL4','C(64)') 
 +              ->addAttribute(array('CHARACTER SET'=>'"ascii"')) 
 +              ->addAttribute(array('COLLATE'=>'"latin1_swedish_ci"'),'mysql');
  
 $t->addColumnObject('COL5',"ENUM('cats','dogs','fish')"); $t->addColumnObject('COL5',"ENUM('cats','dogs','fish')");
-$t->addColumnObject('COL6','T')->addAttribute('DEFTIMESTAMP');+$t->addColumnObject('COL6','T') 
 +              ->addAttribute('DEFTIMESTAMP');
  
-$t->addColumnObject('COL7','D')->addAttribute('DEFDATE');+$t->addColumnObject('COL7','D') 
 +              ->addAttribute('DEFDATE');
  
-$t->addIndexObject('COL4-INDEX')->addIndexItem('COL4')->addAttribute('ASC'); +$t->addIndexObject('COL4-INDEX') 
-$t->addIndexObject('COL4-INDEX')->addIndexItem('COL5');+              ->addIndexItem('COL4') 
 +              ->addAttribute('ASC'); 
 +$t->addIndexObject('COL4-INDEX') 
 +              ->addIndexItem('COL5');
  
 $sql = $dict->createTableSql($tabledef); $sql = $dict->createTableSql($tabledef);
Line 110: Line 125:
 $t = new metaObjectStructure($dict,'employees'); $t = new metaObjectStructure($dict,'employees');
 $sqlarray = $dict->dropTableSql($t); $sqlarray = $dict->dropTableSql($t);
 +</code>
 +
 +==== renameTableSql ====
 +=== Usage ===
 +<code php>
 +$t = new metaObjectStructure($dict,'employees');
 +$t->setNewName('new-column');
 +$sqlarray = $dict->renameTableSql($t);
 </code> </code>
  
  
v5/dictionary/structure/sample_usage.1460230587.txt.gz · Last modified: 2017/04/21 11:29 (external edit)