| Versionen | |
|---|---|
| drupal7 | public DatabaseSchema::columnExists($table, $column) |
Check if a column exists in the given table.
includes/
<?php
public function columnExists($table, $column) {
$condition = $this->buildTableNameCondition($this->connection->prefixTables('{' . $table . '}'));
$condition->condition('column_name', $column);
$condition->compile($this->connection);
// Normally, we would heartily discourage the use of string
// concatination for conditionals like this however, we
// couldn't use db_select() here because it would prefix
// information_schema.tables and the query would fail.
// Don't use {} around information_schema table.
return db_query("SELECT column_name FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchAllKeyed(0, 0);
}
?>
Kommentare
Kommentar hinzufügen