maybe_create_table() – Creates a table in the database if it doesn’t already exist.

Description

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

Usage

$bool = maybe_create_table( $table_name, $create_ddl );

Parameters

$table_name
( string ) required – Database table name.
$create_ddl
( string ) required – SQL statement to create table.

Returns

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

Source

File name: wordpress/wp-admin/install-helper.php


Lines:

1 to 23 of 23
  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.
    // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
    $wpdb->query( $create_ddl );

    // We cannot directly tell whether this succeeded!
    foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
      if ( $table === $table_name ) {
        return true;
      }
    }

    return false;
  }
 

 View on GitHub View on Trac

Called by

    Invoked by

      Calls

      Call hooks

      API Letters: ,,