public function getTableColumns($create = true) { global $db; // Make sure we have a table set if ($this->table == "") { error_out("No table set."); return false; } $sql = new SQLQuery($this->table); $sql->international = $this->international; $columns = $sql->get_columns(); if (!empty($columns)) { // Table exists -- return the columns $this->tablecolumns = $columns; // If table exists and create is set, add any additional columns if ($create) { $formcolumns = $this->formToTableColumns(false); $newcolumns = array_diff(array_keys($formcolumns), array_keys($columns)); if (!empty($newcolumns)) { $tablename = $this->table; if ($this->schema != "") { $tablename = $this->schema . "." . $this->table; } $alter_table_column_string = ""; foreach ($newcolumns as $colname) { if ($alter_table_column_string != "") { $alter_table_column_string .= ","; } $alter_table_column_string .= $colname . " " . $formcolumns[$colname]; $this->tablecolumns[$colname] = $formcolumns[$colname]; } $alter_table_query = "ALTER TABLE " . $tablename . " ADD(" . $alter_table_column_string . ")"; $ret = $db->execute($alter_table_query); } } return $this->tablecolumns; } else { if ($create) { // Table doesn't exist -- create it from form $this->tablecolumns = $this->formToTableColumns(); $sql_create = new SQLCreate($this->table, $this->tablecolumns); $sql_create->international = $this->international; $sql_create->execute(); return $this->tablecolumns; } else { // Table doesn't exist, 'create' set to false: return false error_out("Table doesn't exist."); return false; } } }