WordPress at a glance
function is not described

maybe_create_table() WP 1.0.0

Creates a table in the database if it doesn't already exist.

This method checks for an existing database and creates a new one if it's not already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses to query all tables first and then run the SQL statement creating the table.

  • Global. wpdb. $wpdb

No Hooks.

Return

true/false. If table already exists or was created by function.

Usage

maybe_create_table( $table_name, $create_ddl );
$table_name(string) (required)
Database table name to create.
$create_ddl(string) (required)
SQL statement to create table.

Code of maybe create table: wp-admin/includes/upgrade.php VER 5.1.1

<?php
function maybe_create_table( $table_name, $create_ddl ) {
	global $wpdb;

	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );

	if ( $wpdb->get_var( $query ) == $table_name ) {
		return true;
	}

	// Didn't find it try to create it..
	$wpdb->query( $create_ddl );

	// We cannot directly tell that whether this succeeded!
	if ( $wpdb->get_var( $query ) == $table_name ) {
		return true;
	}
	return false;
}