Exemplo n.º 1
0
 /**
  * @param Database $db
  * @param Table $tbl
  * @return Table
  */
 public function getTableFields(Database $db, Table $tbl)
 {
     $query = sprintf('SHOW COLUMNS IN `%s` FROM `%s`', $tbl->getName(), $db->getName());
     $stmt = $this->conn->query($query);
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $field = new Field('', $row['Field']);
         $field->setType($row['Type'])->setNullable(strtoupper($row['Null']) == 'YES')->setDefaultValue($row['Default']);
         if ($row['Extra']) {
             if ($row['Extra'] == 'auto_increment') {
                 $field->setAutoIncrement(true);
             } else {
                 //things like on update?
                 $field->setExtraString($row['Extra']);
             }
         }
         $tbl->addField($field, true);
     }
     return $tbl;
 }
Exemplo n.º 2
0
 /**
  * @param Table $table
  * @param Database $db
  * @return Table
  */
 protected function addCreateStatement(Table $table, Database $db)
 {
     $stmt = $this->conn->query(sprintf('SHOW CREATE TABLE %s.%s', $db->getName(), $table->getName()));
     $create = $stmt->fetch(\PDO::FETCH_ASSOC);
     if (!$create || !isset($create['Create Table'])) {
         return null;
     }
     $table->setStatement($create['Create Table'])->parse($create['Create Table']);
     $db->addTable($table);
     return $table;
 }