Last active
August 29, 2015 14:10
-
-
Save keopx/c8a32cf1da8ad96c1822 to your computer and use it in GitHub Desktop.
Adding multiple new fields to a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// @see: https://www.drupal.org/node/150215 | |
/** | |
* Add new fields to 'mytable' table. | |
*/ | |
function MYMODULE_update_7001() { | |
$fields = array( | |
'field_name_1' => array( | |
'description' => 'Field name 1', | |
'type' => 'varchar', | |
'length' => '32', | |
'not null' => FALSE, | |
'default' => '', | |
), | |
'field_name_2'=> array( | |
'description' => 'Field name 2', | |
'type' => 'varchar', | |
'length' => '32', | |
'not null' => FALSE, | |
'default' => '', | |
), | |
'field_name_3' => array( | |
'description' => 'Field name 3', | |
'type' => 'varchar', | |
'length' => '128', | |
'not null' => FALSE, | |
'default' => '', | |
), | |
); | |
foreach ($fields as $key => $field) { | |
if (!db_field_exists('mytable', $key)) { | |
db_add_field('mytable', $key, $field); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment