function db_field_exists

Same name in other branches
  1. 7.x includes/database/database.inc \db_field_exists()

Checks if a column exists in the given table.

Parameters

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

$field: The name of the field.

Return value

bool TRUE if the given column 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 fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field);

See also

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

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

Related topics

1 call to db_field_exists()
DatabaseLegacyTest::testDbFieldExists in core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
Tests deprecation of the db_field_exists() function.

File

core/includes/database.inc, line 726

Code

function db_field_exists($table, $field) {
    @trigger_error('db_field_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
    return Database::getConnection()->schema()
        ->fieldExists($table, $field);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.