public function create() { if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) { return false; } /// TO DO : implementing create method by structure $sql = "CREATE " . $this->table . " (" . CRLF; foreach ($this->structure as $field => $attributes) { $sql .= $field; $type = $length = $isNull = $default = ""; foreach ($attributes as $attr => $value) { if ($attr == "type") { // Type casting $type = POD::fieldType($type); } if ($attr == "isNull") { $isNull = $value; } if ($attr == "default") { $default = $value; } } $sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . $default . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . CRLF; } $sql .= ")"; return POD::execute($sql); }
public function create() { if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) { return false; } /// TO DO : implementing create method by structure $this->_called = true; $sql = "CREATE TABLE " . $this->_getTableName() . " (" . CRLF; $keys = array(); foreach ($this->structure as $field => $attributes) { $type = $length = $isNull = $default = ""; foreach ($attributes as $attr => $value) { if ($attr == "type") { // Type casting $type = POD::fieldType($value); } if ($attr == "isNull") { $isNull = $value; } if ($attr == "default") { $default = $value; } if ($attr == "length") { $length = intval($value); } if ($attr == "autoincrement") { $ai = $value; } if ($attr == "index" && $value == true) { array_push($keys, $field); } } $sql .= $field; $sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . POD::escapeString($default) . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . (isset($ai) && $ai == true ? ' AUTO INCREMENT' : '') . ','; } $sql = rtrim($sql, ","); if (is_array($this->option) && array_key_exists('primary', $this->option)) { $sql .= ', PRIMARY KEY (' . implode(',', $this->option['primary']) . ')'; } foreach ($keys as $key) { $sql .= ', KEY (' . POD::escapeString($key) . ')'; } $sql .= ")"; $result = POD::execute($sql); $this->_manage_pool_stack(); return $result; }