Skip to content

Instantly share code, notes, and snippets.

@HellBz
Last active August 29, 2015 14:00
Show Gist options
  • Save HellBz/88044849d258a16a216f to your computer and use it in GitHub Desktop.
Save HellBz/88044849d258a16a216f to your computer and use it in GitHub Desktop.
<?php
function db_add_column($database, $column, $column_attr = "VARCHAR( 255 ) NULL" ){
global $db;
$exists = false;
$columns = db("show columns from ".$database);
while($c = _fetch($columns)){
if($c['Field'] == $column){
$exists = true;
break;
}
}
if(!$exists){
db("ALTER TABLE `".$database."` ADD `".$column."` ".$column_attr);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment