/** * Return an array of columns and their details for a table. */ public static function table_info($table) { $out = array(); switch (DBMan::driver()) { case 'sqlite': $res = db_fetch_array('pragma table_info(' . $table . ')'); foreach ($res as $row) { $type = DBMan::parse_type($row->type); $out[] = (object) array('name' => $row->name, 'type' => $type['type'], 'length' => $type['length'], 'notnull' => $row->notnull == 1 ? 'No' : 'Yes', 'key' => $row->pk == 1 ? 'Primary' : '', 'default' => trim($row->dflt_value, '"'), 'extra' => '', 'original' => $row); } break; case 'mysql': $res = db_fetch_array('describe `' . $table . '`'); foreach ($res as $row) { $type = DBMan::parse_type($row->Type); $out[] = (object) array('name' => $row->Field, 'type' => $type['type'], 'length' => $type['length'], 'notnull' => $row->Null == 'NO' ? 'No' : 'Yes', 'key' => $row->Key == 'PRI' ? 'Primary' : !empty($row->Key) ? 'Secondary' : '', 'default' => $row->Default, 'extra' => $row->Extra, 'original' => $row); } } return $out; }