core/Mysql.php
public function addField(string $tbname, string $field, array $options = [])
    {
        $options = array_merge([
            'type' => 'VARCHAR',
            'len' => 250,
            'scale' => 0,
            'def' => null,
            'comment' => '',
        ], $options);

        list($type, $len, $scale, $def, $comment) = array_values($options);
        $type = strtoupper($type);
        $sql = "ALTER TABLE {$tbname} ADD `{$field}`";
        switch ($type) {
            case 'VARCHAR':
            case 'INT':
            case 'BIGINT':
            case 'SMALLINT':
            case 'INTEGER':
            case 'TINYINT':
                $sql .= $type . '(' . $len . ')';
                break;
            case 'DECIMAL':
            case 'DOUBLE':
            case 'FLOAT':
                $sql .= $type . '(' . $len . ',' . $scale . ')';
                break;
            default:
                $sql .= $type;
                break;
        }
        $sql .= ' DEFAULT ' . Mysql::escape($def);
        if ($comment) {
            $sql .= ' COMMENT ' . Mysql::escape($comment);
        }
        $sql .= ';';
        return $this->exec($sql);
    }
public function addField(string $tbname, string $field, array $options = [])
    {
        $options = array_merge([
            'type' => 'VARCHAR',
            'len' => 250,
            'scale' => 0,
            'def' => null,
            'comment' => '',
        ], $options);

        list($type, $len, $scale, $def, $comment) = array_values($options);
        $type = strtoupper($type);
        $sql = "ALTER TABLE {$tbname} ADD `{$field}`";
        switch ($type) {
            case 'VARCHAR':
            case 'INT':
            case 'BIGINT':
            case 'SMALLINT':
            case 'INTEGER':
            case 'TINYINT':
                $sql .= $type . '(' . $len . ')';
                break;
            case 'DECIMAL':
            case 'DOUBLE':
            case 'FLOAT':
                $sql .= $type . '(' . $len . ',' . $scale . ')';
                break;
            default:
                $sql .= $type;
                break;
        }
        $sql .= ' DEFAULT ' . Mysql::escape($def);
        if ($comment) {
            $sql .= ' COMMENT ' . Mysql::escape($comment);
        }
        $sql .= ';';
        return $this->exec($sql);
    }
添加字段
@param string $tbname
@param string $field
@param array $options
@return int
@throws MysqlException