db_column_exists

6 database.pgsql.inc db_column_exists($table, $column)
6 database.mysqli.inc db_column_exists($table, $column)
6 database.mysql.inc db_column_exists($table, $column)

Check if a column exists in the given table.

Parameters

$table: The name of the table.

$column: The name of the column.

Return value

TRUE if the column exists, and FALSE if the column does not exist.

Related topics

1 call to db_column_exists()

File

includes/database.pgsql.inc, line 407
Database interface code for PostgreSQL database servers.

Code

function db_column_exists($table, $column) {
  return (bool) db_result(db_query("SELECT COUNT(pg_attribute.attname) FROM pg_class, pg_attribute WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relname = '{" . db_escape_table($table) . "}' AND attname = '" . db_escape_table($column) . "'"));
}

Comments

See also: db_table_exists

If you call db_column_exists using a $table which does not exist you will get an error message, so check first with db_table_exists.

In D7

Login or register to post comments