Definition:
function maybe_add_column($table_name, $column_name, $create_ddl) {}
Add column to database table, if column doesn’t already exist in table.
Parameters
- string $table_name: Database table name
- string $column_name: Table column name
- string $create_ddl: SQL to add column to table.
Return values
returns:False on failure. True, if already exists or was successful.
Source code
function maybe_add_column($table_name, $column_name, $create_ddl) { global $wpdb, $debug; foreach ($wpdb->get_col("DESC $table_name",0) as $column ) { if ($debug) echo("checking $column == $column_name<br />"); if ($column == $column_name) { return true; } } //didn't find it try to create it. $wpdb->query($create_ddl); // we cannot directly tell that whether this succeeded! foreach ($wpdb->get_col("DESC $table_name",0) as $column ) { if ($column == $column_name) { return true; } } return false; }
2325
No comments yet... Be the first to leave a reply!