db_table_exists

5 database.pgsql.inc db_table_exists($table)
5 database.mysqli.inc db_table_exists($table)
5 database.mysql.inc db_table_exists($table)
6 database.mysqli.inc db_table_exists($table)
6 database.pgsql.inc db_table_exists($table)
6 database.mysql.inc db_table_exists($table)
7 database.inc db_table_exists($table)
8 database.inc db_table_exists($table)

Check if a table exists.

Parameters

$table: The name of the table.

Return value

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

Related topics

16 calls to db_table_exists()

File

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

Code

function db_table_exists($table) {
  return (bool) db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '{" . db_escape_table($table) . "}'"));
}

Comments

postgres db_table_exists

In postgres you have to take into account that the table name ( and any other identifier ) is lowercase, despite the name you give
So, if you use the Drupal schema API and creates a table, then later, if you want to check if that table exists you have to do something like:

db_table_exists(strtolower($table))

because in the pg_class, the field relname content will be ALWAYS lowercase.

This transformation, btw, it could be added to db_escape_table save us a bit of time :-)

Login or register to post comments