function 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

TRUE if the given column exists, otherwise FALSE.

Related topics

10 calls to db_field_exists()
comment_update_8001 in drupal/core/modules/comment/comment.install
Create a UUID column for comments.
field_sql_storage_update_8000 in drupal/core/modules/field/modules/field_sql_storage/field_sql_storage.install
Changes field language into langcode.
node_update_8004 in drupal/core/modules/node/node.install
Create a UUID column for nodes.
RegressionTest::testDBFieldExists in drupal/core/modules/system/lib/Drupal/system/Tests/Database/RegressionTest.php
Tests the db_field_exists() function.
SchemaTest::testUnsignedColumns in drupal/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php
Tests creating unsigned columns and data integrity thereof.

... See full list

File

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

Code

function db_field_exists($table, $field) {
  return Database::getConnection()
    ->schema()
    ->fieldExists($table, $field);
}