SqlHandler::move_column PHP Method

move_column() protected static method

Move a single column from one table to another
protected static move_column ( $old_table, $new_table, $column_name )
$old_table
$new_table
$column_name
    protected static function move_column($old_table, $new_table, $column_name)
    {
        $result = dbquery("SHOW COLUMNS FROM " . $old_table);
        $data = array();
        if (dbrows($result) > 0) {
            $i = 1;
            while ($data = dbarray($result)) {
                if ($data['Field'] == $column_name) {
                    break;
                }
            }
        }
        if (!empty($data)) {
            $result = dbquery("ALTER TABLE " . $new_table . " ADD COLUMN " . $data['Field'] . " " . $data['Type'] . " " . ($data['Null'] == "NO" ? "NOT NULL" : "NULL") . " DEFAULT '" . $data['Default'] . "'");
            if (!$result) {
                \defender::stop();
            }
            if ($result && \defender::safe()) {
                dbquery("INSERT INTO " . $new_table . " (" . $data['Field'] . ") SELECT " . $data['Field'] . " FROM " . $old_table);
            }
            if (!$result && \defender::safe()) {
                \defender::stop();
            }
            if (!\defender::safe()) {
                addNotice("danger", "Cannot move " . $column_name);
            }
        }
    }