public function create_table_sql(\ebi\Dao $dao) { $columndef = $primary = []; $sql = 'create table ' . $this->quotation($dao->table()) . '(' . PHP_EOL; foreach ($dao->columns(true) as $prop_name => $column) { if ($this->create_table_prop_cond($dao, $prop_name)) { $column_str = ' ' . $this->to_column_type($dao, $dao->prop_anon($prop_name, 'type'), $column->column()) . ' null '; $columndef[] = $column_str; if ($dao->prop_anon($prop_name, 'primary') === true || $dao->prop_anon($prop_name, 'type') == 'serial') { $primary[] = $this->quotation($column->column()); } } } $sql .= implode(',' . PHP_EOL, $columndef) . PHP_EOL; $sql .= ' );' . PHP_EOL; return $sql; }
/** * create table */ public function create_table_sql(\ebi\Dao $dao) { $columndef = $primary = []; $sql = 'create table ' . $this->quotation($dao->table()) . '(' . PHP_EOL; foreach ($dao->columns(true) as $prop_name => $column) { if ($this->create_table_prop_cond($dao, $prop_name)) { $column_str = ' ' . $this->to_column_type($dao, $dao->prop_anon($prop_name, 'type'), $column->column()) . ' null '; $columndef[] = $column_str; if ($dao->prop_anon($prop_name, 'primary') === true || $dao->prop_anon($prop_name, 'type') == 'serial') { $primary[] = $this->quotation($column->column()); } } } $sql .= implode(',' . PHP_EOL, $columndef) . PHP_EOL; if (!empty($primary)) { $sql .= ' ,primary key ( ' . implode(',', $primary) . ' ) ' . PHP_EOL; } $sql .= ' ) engine = InnoDB character set utf8 collate utf8_general_ci;' . PHP_EOL; return $sql; }
public function create_sql(\ebi\Dao $dao) { $insert = $vars = []; $autoid = null; foreach ($dao->columns(true) as $column) { if (!$column->auto()) { $insert[] = $this->quotation($column->column()); $vars[] = $this->column_value($dao, $column->name(), $dao->{$column->name()}()); } } return new \ebi\Daq('insert into ' . $this->quotation($column->table()) . ' (' . implode(',', $insert) . ') values (' . implode(',', array_fill(0, sizeof($insert), '?')) . ');', $vars); }