add_column() public method

Add a column
public add_column ( string $table_name, string $column_name, string $type, array $options = [] ) : boolean
$table_name string the table name
$column_name string the column name
$type string the column type
$options array column options
return boolean
 /**
  * test adding column
  */
 public function test_add_column()
 {
     //create it
     $table = $this->adapter->create_table('users');
     $table->column('name', 'string', array('limit' => 20));
     $table->finish();
     $col = $this->adapter->column_info("users", "name");
     $this->assertEquals("name", $col['field']);
     //add column
     $this->adapter->add_column("users", "fav_color", "string", array('limit' => 32));
     $col = $this->adapter->column_info("users", "fav_color");
     $this->assertEquals("fav_color", $col['field']);
     $this->assertEquals('character varying(32)', $col['type']);
     //add column
     $this->adapter->add_column("users", "latitude", "decimal", array('precision' => 10, 'scale' => 2));
     $col = $this->adapter->column_info("users", "latitude");
     $this->assertEquals("latitude", $col['field']);
     $this->assertEquals('numeric(10,2)', $col['type']);
     //add column with unsigned parameter
     $this->adapter->add_column("users", "age", "integer", array('limit' => 2));
     // the limit will be ignored
     $col = $this->adapter->column_info("users", "age");
     $this->assertEquals("age", $col['field']);
     $this->assertEquals('integer', $col['type']);
     //add column with biginteger datatype
     $this->adapter->add_column("users", "weight", "biginteger");
     $col = $this->adapter->column_info("users", "weight");
     $this->assertEquals("weight", $col['field']);
     $this->assertEquals('bigint', $col['type']);
     $this->drop_table('users');
 }
Beispiel #2
0
 /**
  * Add a column
  *
  * @param string $table_name the name of the table
  * @param string $column_name the column name
  * @param string $type the column type
  * @param array|string $options
  *
  * @return boolean
  */
 public function add_column($table_name, $column_name, $type, $options = array())
 {
     return $this->_adapter->add_column($table_name, $column_name, $type, $options);
 }