Skip to content

Instantly share code, notes, and snippets.

@daviddeutsch
Last active December 20, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddeutsch/6147167 to your computer and use it in GitHub Desktop.
Save daviddeutsch/6147167 to your computer and use it in GitHub Desktop.
widenColumn
<?php
// MySQL::widenColumn
// Original Function
public function widenColumn($type, $column, $datatype) {
$table = $type;
$type = $datatype;
$table = $this->esc($table);
$column = $this->esc($column);
$newtype = array_key_exists($type, $this->typeno_sqltype) ? $this->typeno_sqltype[$type] : '';
$changecolumnSQL = "ALTER TABLE $table CHANGE $column $column $newtype ";
$this->adapter->exec($changecolumnSQL);
}
// Make space
public function widenColumn( $type, $column, $datatype )
{
$table = $type;
$type = $datatype;
$table = $this->esc($table);
$column = $this->esc($column);
$newtype = array_key_exists($type, $this->typeno_sqltype) ? $this->typeno_sqltype[$type] : '';
$sql = "ALTER TABLE $table CHANGE $column $column $newtype ";
$this->adapter->exec($sql);
}
// Reduce variable confusion
public function widenColumn( $table, $column, $datatype )
{
$table = $this->esc($table);
$column = $this->esc($column);
$newtype = array_key_exists($datatype, $this->typeno_sqltype) ? $this->typeno_sqltype[$datatype] : '';
$sql = "ALTER TABLE $table CHANGE $column $column $newtype ";
$this->adapter->exec($sql);
}
// 80 Char limit
public function widenColumn( $table, $column, $datatype )
{
$table = $this->esc($table);
$column = $this->esc($column);
$newtype = '';
if ( !array_key_exists($datatype, $this->typeno_sqltype) ) {
$newtype = $this->typeno_sqltype[$datatype];
}
$sql = "ALTER TABLE"
. $table
. "CHANGE"
. ' '.$column
. ' '.$column
. ' '.$newtype
.' ';
$this->adapter->exec($sql);
}
// Further collapse variables
public function widenColumn( $table, $column, $datatype )
{
$table = $this->esc($table);
$column = $this->esc($column);
$newtype = '';
if ( !array_key_exists($datatype, $this->typeno_sqltype) ) {
$newtype = $this->typeno_sqltype[$datatype];
}
$sql = "ALTER TABLE"
. $table
. "CHANGE"
. ' '.$column
. ' '.$column
. ' '.$newtype
.' ';
$this->adapter->exec($sql);
}
// You know what? If there's no type, there's no change!
public function widenColumn( $table, $column, $datatype )
{
if ( !array_key_exists($datatype, $this->typeno_sqltype) ) {
return;
}
$table = $this->esc($table);
$column = $this->esc($column);
$sql = "ALTER TABLE"
. $table
. "CHANGE"
. ' '.$column
. ' '.$column
. ' '.$this->typeno_sqltype[$datatype]
.' ';
$this->adapter->exec($sql);
}
// Collapse last variable
public function widenColumn( $table, $column, $datatype )
{
if ( !array_key_exists($datatype, $this->typeno_sqltype) ) return;
$table = $this->esc($table);
$column = $this->esc($column);
$this->adapter->exec(
"ALTER TABLE $table CHANGE $column"
. " $column " . $this->typeno_sqltype[$datatype]
);
}
// Actually, isset is shorter and more accurate (returns false on a null value)
public function widenColumn( $table, $column, $datatype )
{
if ( !isset($this->typeno_sqltype[$datatype]) ) return;
$table = $this->esc($table);
$column = $this->esc($column);
$this->adapter->exec(
"ALTER TABLE $table CHANGE $column"
. " $column " . $this->typeno_sqltype[$datatype]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment