maybe_create_table

Advertisement

Summery Summery

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

Syntax Syntax

maybe_create_table( string $table_name, string $create_ddl )

Parameters Parameters

$table_name

(Required) Database table name.

$create_ddl

(Required) SQL statement to create table.

Return Return

(bool) True on success or if the table already exists. False on failure.

Source Source

File: wp-admin/install-helper.php

	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, so 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;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Advertisement

Leave a Reply