(PHP 4, PHP 5, PHP 7, PHP 8)
odbc_tables — Get the list of table names stored in a specific data source
odbc_tables( Odbc\Connection $odbc, ?string $catalog = null, ?string $schema = null, ?string $table = null, ?string $types = null ): Odbc\Result|false
Lists all tables in the requested range.
To support enumeration of qualifiers, owners, and table types, the following special semantics for the catalog, schema, table, and table_type are available:
catalog is a single percent character (%) and schema and table are empty strings, then the result set contains a list of valid qualifiers for the data source. (All columns except the TABLE_QUALIFIER column contain NULLs.) schema is a single percent character (%) and catalog and table are empty strings, then the result set contains a list of valid owners for the data source. (All columns except the TABLE_OWNER column contain NULLs.) table_type is a single percent character (%) and catalog, schema and table are empty strings, then the result set contains a list of valid table types for the data source. (All columns except the TABLE_TYPE column contain NULLs.) odbcThe ODBC connection object, see odbc_connect() for details.
catalogThe catalog ('qualifier' in ODBC 2 parlance).
schema The schema ('owner' in ODBC 2 parlance). This parameter accepts the following search patterns: % to match zero or more characters, and _ to match a single character.
table The name. This parameter accepts the following search patterns: % to match zero or more characters, and _ to match a single character.
types If table_type is not an empty string, it must contain a list of comma-separated values for the types of interest; each value may be enclosed in single quotes (') or unquoted. For example, 'TABLE','VIEW' or TABLE, VIEW. If the data source does not support a specified table type, odbc_tables() does not return any results for that type.
Returns an ODBC result object containing the information or false on failure.
The result set has the following columns:
TABLE_CATTABLE_SCHEMTABLE_NAMETABLE_TYPEREMARKS The result set is ordered by TABLE_TYPE, TABLE_CAT, TABLE_SCHEM and TABLE_NAME.
| Version | Description |
|---|---|
| 8.4.0 | odbc expects an Odbc\Connection instance now; previously, a resource was expected. |
| 8.4.0 | This function returns an Odbc\Result instance now; previously, a resource was returned. |
| 8.0.0 | schema, table and types are now nullable. |
Example #1 List Tables in a Catalog
<?php
$conn = odbc_connect($dsn, $user, $pass);
$tables = odbc_tables($conn, 'SalesOrders', 'dbo', '%', 'TABLE');
while (($row = odbc_fetch_array($tables))) {
print_r($row);
break; // further rows omitted for brevity
}
?> The above example will output something similar to:
Array
(
[TABLE_CAT] => SalesOrders
[TABLE_SCHEM] => dbo
[TABLE_NAME] => Orders
[TABLE_TYPE] => TABLE
[REMARKS] =>
)
© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.odbc-tables.php