public function renameColumn($name, $new_name)
    {
        $existing_columns = $this->getCols(true);
        // check if column is already existing
        if (!in_array($name, array_keys($existing_columns)))
            trigger_error('cannot rename column. it does not exist.',E_USER_ERROR);
        if (in_array($new_name, array_keys($existing_columns)))
            trigger_error('cannot rename column. new column already exist.',E_USER_ERROR);

        if (preg_match('/sqlite2?/', $this->db->driver()))
            // SQlite does not support drop or rename column directly
            $this->rebuild_cmd['rename'][$name] = $new_name;
        elseif (preg_match('/odbc/', $this->db->driver())) {
            // no rename column for odbc, create temp column
            $this->addColumn($new_name, $existing_columns[$name])->passThrough();
            $this->queries[] = "UPDATE $this->name SET $new_name = $name";
            $this->dropColumn($name);
        } else {
            $existing_columns = $this->getCols(true);
            $quotedTable = $this->db->quotekey($this->name);
            $quotedColumn = $this->db->quotekey($name);
            $quotedColumnNew = $this->db->quotekey($new_name);
            $cmd = array(
                'mysql' =>
                    "ALTER TABLE $quotedTable CHANGE $quotedColumn $quotedColumnNew ".$existing_columns[$name]['type'].";",
                'pgsql|ibm' =>
                    "ALTER TABLE $quotedTable RENAME COLUMN $quotedColumn TO $quotedColumnNew;",
                'mssql|sybase|dblib|sqlsrv' =>
                    "sp_rename [$this->name.$name], '$new_name', 'Column'",
            );
            if (preg_match('/mssql|sybase|dblib|sqlsrv/', $this->db->driver()))
                $this->suppress = true;
            $this->queries[] = $this->findQuery($cmd);
        }
    }
public function renameColumn($name, $new_name)
    {
        $existing_columns = $this->getCols(true);
        // check if column is already existing
        if (!in_array($name, array_keys($existing_columns)))
            trigger_error('cannot rename column. it does not exist.',E_USER_ERROR);
        if (in_array($new_name, array_keys($existing_columns)))
            trigger_error('cannot rename column. new column already exist.',E_USER_ERROR);

        if (preg_match('/sqlite2?/', $this->db->driver()))
            // SQlite does not support drop or rename column directly
            $this->rebuild_cmd['rename'][$name] = $new_name;
        elseif (preg_match('/odbc/', $this->db->driver())) {
            // no rename column for odbc, create temp column
            $this->addColumn($new_name, $existing_columns[$name])->passThrough();
            $this->queries[] = "UPDATE $this->name SET $new_name = $name";
            $this->dropColumn($name);
        } else {
            $existing_columns = $this->getCols(true);
            $quotedTable = $this->db->quotekey($this->name);
            $quotedColumn = $this->db->quotekey($name);
            $quotedColumnNew = $this->db->quotekey($new_name);
            $cmd = array(
                'mysql' =>
                    "ALTER TABLE $quotedTable CHANGE $quotedColumn $quotedColumnNew ".$existing_columns[$name]['type'].";",
                'pgsql|ibm' =>
                    "ALTER TABLE $quotedTable RENAME COLUMN $quotedColumn TO $quotedColumnNew;",
                'mssql|sybase|dblib|sqlsrv' =>
                    "sp_rename [$this->name.$name], '$new_name', 'Column'",
            );
            if (preg_match('/mssql|sybase|dblib|sqlsrv/', $this->db->driver()))
                $this->suppress = true;
            $this->queries[] = $this->findQuery($cmd);
        }
    }
public function renameColumn ( $ name , $ new_name ) { $ existing_columns = $ this -> getCols ( true ) ; // check if column is already existing if ( ! in_array ( $ name , array_keys ( $ existing_columns ) ) ) trigger_error ( 'cannot rename column. it does not exist.' , E_USER_ERROR ) ; if ( in_array ( $ new_name , array_keys ( $ existing_columns ) ) ) trigger_error ( 'cannot rename column. new column already exist.' , E_USER_ERROR ) ; if ( preg_match ( '/sqlite2?/' , $ this -> db -> driver ( ) ) ) // SQlite does not support drop or rename column directly $ this -> rebuild_cmd [ 'rename' ] [ $ name ] = $ new_name ; elseif ( preg_match ( '/odbc/' , $ this -> db -> driver ( ) ) ) { // no rename column for odbc, create temp column $ this -> addColumn ( $ new_name , $ existing_columns [ $ name ] ) -> passThrough ( ) ; $ this -> queries [ ] = "UPDATE $this->name SET $new_name = $name" ; $ this -> dropColumn ( $ name ) ; } else { $ existing_columns = $ this -> getCols ( true ) ; $ quotedTable = $ this -> db -> quotekey ( $ this -> name ) ; $ quotedColumn = $ this -> db -> quotekey ( $ name ) ; $ quotedColumnNew = $ this -> db -> quotekey ( $ new_name ) ; $ cmd = array ( 'mysql' => "ALTER TABLE $quotedTable CHANGE $quotedColumn $quotedColumnNew " . $ existing_columns [ $ name ] [ 'type' ] . ";" , 'pgsql|ibm' => "ALTER TABLE $quotedTable RENAME COLUMN $quotedColumn TO $quotedColumnNew;" , 'mssql|sybase|dblib|sqlsrv' => "sp_rename [$this->name.$name], '$new_name', 'Column'" , ) ; if ( preg_match ( '/mssql|sybase|dblib|sqlsrv/' , $ this -> db -> driver ( ) ) ) $ this -> suppress = true ; $ this -> queries [ ] = $ this -> findQuery ( $ cmd ) ; } }
rename a column
@param $name
@param $new_name
@return void
rename a column