SqlHandler::transfer_table PHP Method

transfer_table() protected static method

Move old table to new table.
protected static transfer_table ( $old_table, $new_table )
$old_table
$new_table
    protected static function transfer_table($old_table, $new_table)
    {
        $old_table = !stristr($old_table, DB_PREFIX) ? DB_PREFIX . $old_table : $old_table;
        $new_table = !stristr($old_table, DB_PREFIX) ? DB_PREFIX . $new_table : $new_table;
        $result = dbquery("SHOW COLUMNS FROM " . $old_table);
        if (dbrows($result) > 0) {
            $i = 1;
            while ($data = dbarray($result)) {
                if ($data['Key'] !== "PRI" && $i > 2) {
                    $result = dbquery("ALTER TABLE " . $new_table . " ADD COLUMN " . $data['Field'] . " " . $data['Type'] . " " . ($data['Null'] == "NO" ? "NOT NULL" : "NULL") . " DEFAULT '" . $data['Default'] . "'");
                    if (!$result && \defender::safe()) {
                        dbquery("INSERT INTO " . $new_table . " (" . $data['Field'] . ") SELECT " . $data['Field'] . " FROM " . $old_table);
                    }
                }
                $i++;
            }
            if (!\defender::safe()) {
                addNotice("danger", "Unable to move all columns from " . $old_table . " to " > $new_table);
            }
        }
    }