You are here

function db_table_exists in Drupal 8

Same name and namespace in other branches
  1. 5 includes/database.mysqli.inc \db_table_exists()
  2. 5 includes/database.mysql.inc \db_table_exists()
  3. 5 includes/database.pgsql.inc \db_table_exists()
  4. 6 includes/database.mysqli.inc \db_table_exists()
  5. 6 includes/database.mysql.inc \db_table_exists()
  6. 6 includes/database.pgsql.inc \db_table_exists()
  7. 7 includes/database/database.inc \db_table_exists()

Checks if a table exists.

Parameters

string $table: The name of the table in drupal (no prefixing).

Return value

bool TRUE if the given table exists, otherwise FALSE.

Deprecated

in drupal:8.0.0 and is removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call tableExists() on it. For example, $injected_database->schema()->tableExists($table);

See also

https://www.drupal.org/node/2993033

\Drupal\Core\Database\Schema::tableExists()

Related topics

1 call to db_table_exists()
DatabaseLegacyTest::testDbTableExists in core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
Tests the db_table_exists() function.

File

core/includes/database.inc, line 698
Core systems for the database layer.

Code

function db_table_exists($table) {
  @trigger_error('db_table_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
  return Database::getConnection()
    ->schema()
    ->tableExists($table);
}