A HitchHackers guide through WordPress


Home | Pages | Archives


maybe_create_table

February 12, 2011 1:43 am

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

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

Parameters

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

Rate this:

Posted by Thorsten

Categories: /wp-admin/install-helper.php, Documentation, Files, Functions, Functions by letter m

Tags: ,

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.