DBEntity::create PHP Method

create() public method

Create a new entity
public create ( )
    public function create()
    {
        $schema = static::schema();
        $cols = $schema['columns'];
        $colLabels = array();
        $colValues = array();
        foreach ($cols as $col) {
            if (isset($this->{$col})) {
                array_push($colLabels, $col);
                $val = $this->{$col};
                if (is_string($val)) {
                    $val = safeSQLString($val);
                }
                array_push($colValues, $val);
            }
        }
        $result = DBEntity::query('INSERT INTO ' . $this->table() . ' (' . implode(',', $colLabels) . ') VALUES (' . implode(',', $colValues) . ')');
        if ($result == true) {
            /** 
             * Re-select the record to get computed field values
             */
            $insertID = mysql_insert_id();
            if ($insertID != NULL) {
                $this->{$schema->pk} = $insertID;
            }
            $this->reload();
            return true;
        }
        return false;
    }