maybe_create_table

Definition:
function maybe_create_table($table_name, $create_ddl) {}

Create database table, if it doesn’t already exist.

Parameters

  • string $table_name: Database table name.
  • string $create_ddl: Create database table SQL.

Return values

returns:False on error, true if already exists or success.

Source code

function maybe_create_table($table_name, $create_ddl) {

	global $wpdb;

	foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {

		if ($table == $table_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("SHOW TABLES",0) as $table ) {

		if ($table == $table_name) {

			return true;

		}

	}

	return false;

}

2329

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

Leave a comment