Advertisements

maybe_drop_column

Definition:
function maybe_drop_column($table_name, $column_name, $drop_ddl) {}

Drop column from database table, if it exists.

Parameters

  • string $table_name: Table name
  • string $column_name: Column name
  • string $drop_ddl: SQL statement to drop column.

Return values

returns:False on failure, true on success or doesn’t exist.

Source code

function maybe_drop_column($table_name, $column_name, $drop_ddl) {

	global $wpdb;

	foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {

		if ($column == $column_name) {

			//found it try to drop it.

			$wpdb->query($drop_ddl);

			// we cannot directly tell that whether this succeeded!

			foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {

				if ($column == $column_name) {

					return false;

				}

			}

		}

	}

	// else didn't find it

	return true;

}

2333

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: