diff options
author | Andreas Fischer <bantu@phpbb.com> | 2011-10-14 15:25:15 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2011-10-14 16:35:07 +0200 |
commit | 234edf674cd1c2ed3611f69cd925c4d5e29fdc20 (patch) | |
tree | c2ae488bed2f2503b817c1b7dfe9378a08a3c350 /phpBB/includes/db/db_tools.php | |
parent | 1657339e6d0b9a04463ce63fefa6332cab8aad14 (diff) | |
download | forums-234edf674cd1c2ed3611f69cd925c4d5e29fdc20.tar forums-234edf674cd1c2ed3611f69cd925c4d5e29fdc20.tar.gz forums-234edf674cd1c2ed3611f69cd925c4d5e29fdc20.tar.bz2 forums-234edf674cd1c2ed3611f69cd925c4d5e29fdc20.tar.xz forums-234edf674cd1c2ed3611f69cd925c4d5e29fdc20.zip |
[ticket/8240] Add ability to get a list of tables to db_tools.
PHPBB3-8240
Diffstat (limited to 'phpBB/includes/db/db_tools.php')
-rw-r--r-- | phpBB/includes/db/db_tools.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 0d8cf7fdab..7c3d673869 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -348,6 +348,66 @@ class phpbb_db_tools } /** + * Gets a list of tables in the database. + * + * @return array Array of table names (all lower case) + */ + function sql_list_tables() + { + switch ($this->db->sql_layer) + { + case 'mysql': + case 'mysql4': + case 'mysqli': + $sql = 'SHOW TABLES'; + break; + + case 'sqlite': + $sql = 'SELECT name + FROM sqlite_master + WHERE type = "table"'; + break; + + case 'mssql': + case 'mssql_odbc': + case 'mssqlnative': + $sql = "SELECT name + FROM sysobjects + WHERE type='U'"; + break; + + case 'postgres': + $sql = 'SELECT relname + FROM pg_stat_user_tables'; + break; + + case 'firebird': + $sql = 'SELECT rdb$relation_name + FROM rdb$relations + WHERE rdb$view_source is null + AND rdb$system_flag = 0'; + break; + + case 'oracle': + $sql = 'SELECT table_name + FROM USER_TABLES'; + break; + } + + $result = $this->db->sql_query($sql); + + $tables = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $name = current($row); + $tables[$name] = $name; + } + $this->db->sql_freeresult($result); + + return $tables; + } + + /** * Check if table exists * * |