Example #1
0
 public static function getTableMetadata($tableName)
 {
     $columns = array();
     $instance = self::getInstance();
     foreach ($instance->getArray("DESCRIBE {$tableName}") as $columnInfo) {
         $name = $columnInfo['Field'];
         $typeInfo = $instance->parseTypeInfo($columnInfo['Type']);
         $columns[$name] = array('name' => $name, 'table' => $tableName, 'type' => $typeInfo['type'], 'length' => Util::lavnn('length', $typeInfo, ''), 'not_null' => 0 + ($columnInfo['Null'] == 'NO'), 'primary_key' => 0 + ($columnInfo['Key'] == 'PRI'), 'auto_increment' => 0 + ($columnInfo['Extra'] == 'auto_increment'), 'unique_key' => 0 + ($columnInfo['Key'] == 'UNI'), 'multiple_key' => 0 + ($columnInfo['Key'] == 'MUL'), 'fulltext_index' => 0 + ($columnInfo['Key'] == 'TXT'), 'numeric' => 0 + in_array($typeInfo['type'], $instance->getIntegerTypes()) + in_array($typeInfo['type'], $instance->getFloatTypes()), 'blob' => 0 + in_array($typeInfo['type'], $instance->getTextTypes()) + in_array($typeInfo['type'], $instance->getBlobTypes()), 'unsigned' => 0 + $typeInfo['unsigned'], 'quotes' => 0 + Database::needQuotes($typeInfo['type']), 'nullable' => 0 + ($columnInfo['Null'] == 'YES'), 'scale' => Util::lavnn('length', $typeInfo, ''), 'align' => Database::getFieldAlignment($typeInfo['type']), 'enum' => Util::lavnn('enum', $typeInfo, ''), 'default' => $columnInfo['Default']);
     }
     return $columns;
 }