odbc_tables

(PHP 4, PHP 5, PHP 7, PHP 8)

odbc_tablesLista las tablas de una fuente

Descripción

odbc_tables(
    Odbc\Connection $odbc,
    ?string $catalog = null,
    ?string $schema = null,
    ?string $table = null,
    ?string $types = null
): Odbc\Result|false

Lista las tablas de una fuente.

Para soportar las enumeraciones de calificadores propietarios y tipos de tabla, la siguiente semántica para los parámetros catalog, schema, table y table_type está disponible:

  • Si catalog es un signo de porcentaje (%), y schema y table son strings vacíos, entonces el resultado contiene la lista de calificadores válidos para la fuente (todas las columnas excepto TABLE_QUALIFIER contienen NULL).
  • Si schema es un signo de porcentaje (%), y catalog y table son strings vacíos, entonces el resultado contiene la lista de propietarios de la fuente (todas las columnas excepto TABLE_OWNER contienen NULL).
  • Si table_type es un signo de porcentaje (%), y catalog, schema y table son strings vacíos, entonces el resultado contiene la lista de tipos de tablas de la fuente (todas las columnas excepto TABLE_TYPE contienen NULL).

Parámetros

odbc

El conector identificador ODBC, ver odbc_connect() para más información.

catalog

The catalog ('qualifier' in ODBC 2 parlance).

schema

The schema ('owner' in ODBC 2 parlance). Este parámetro acepta los siguientes patrones de búsqueda: "%" para coincidir cero o más caracteres, y "_" para coincidir un solo caracter.

table

El nombre. Este parámetro acepta los siguientes patrones de búsqueda: "%" para coincidir cero o más caracteres, y "_" para coincidir un solo caracter.

types

Si table_type no es un string vacío, debe contener una lista de valores, separados por comas, que representan los tipos buscados. Cada valor puede estar entre comillas simples ('), o sin comillas. Por ejemplo, 'TABLE','VIEW' o TABLE, VIEW. Si la fuente de datos no soporta un tipo de tabla dado, odbc_tables() no devolverá ningún resultado para ese tipo.

Valores devueltos

Returns an ODBC result object que contiene las informaciones o false en caso de error.

El conjunto de resultados contiene las siguientes columnas:

  • TABLE_CAT
  • TABLE_SCHEM
  • TABLE_NAME
  • TABLE_TYPE
  • REMARKS
Drivers can report additional columns.

El conjunto de resultados está ordenado por TABLE_TYPE, TABLE_CAT, TABLE_SCHEM y TABLE_NAME.

Historial de cambios

Versión Descripción
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 y types ahora son anulables.

Ejemplos

Ejemplo #1 Lista las Tablas en un Catálogo

<?php
$conn
= odbc_connect($dsn, $user, $pass);
$tables = odbc_tables($conn, 'SalesOrders', 'dbo', '%', 'TABLE');
while ((
$row = odbc_fetch_array($tables))) {
print_r($row);
break;
// filas adicionales omitidas por brevedad
}
?>

El resultado del ejemplo sería algo similar a:

Array
(
    [TABLE_CAT] => SalesOrders
    [TABLE_SCHEM] => dbo
    [TABLE_NAME] => Orders
    [TABLE_TYPE] => TABLE
    [REMARKS] =>
)

Ver también

add a note

User Contributed Notes 3 notes

up
2
liquidicee at hotmail dot com
24 years ago
Here's how to get a list of all the tables in your database.. with an actual example of how its done and how to get the results.. and you don't need to put in schema and all that other crap

<?php
$conn
= odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (
odbc_fetch_row($tablelist)) {
if (
odbc_result($tablelist, 4) == "TABLE")
echo
odbc_result($tablelist, 3) ."<br>";
}
?>

to understand what the above is doing,
use odbc_result_all($tablelist); this will show you EVERYTHING returned by odbc_tables() then you can look through it and see better how odbc_tables() works and what exactly it returns in the string to get a better idea on how to deal with it.
it would have saved me alot of time if i would have just taken a look at the full string returned by odbc_tables(), so i suggest you take the minute or two and look... here is an example of how to do it..which would have been helpful for me ;x.

<?php
$conn
= odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (
odbc_fetch_row($tablelist)) {
echo
odbc_result_all($tablelist);
}
?>

hopefully this will help some people.. i have alot more to add about this but no time :(
so again hope this helps.
Liquidice
up
0
narcomweb at wanadoo dot fr
19 years ago
Here a Code for listing Table names
<?php
$dbh
= odbc_connect($dsn, $user, $pwd);

$result = odbc_tables($dbh);

$tables = array();
while (
odbc_fetch_row($result)){
if(
odbc_result($result,"TABLE_TYPE")=="TABLE")
echo
"<br>".odbc_result($result,"TABLE_NAME");

}
?>
You don't have views or System tables with.
Only simple tables in your database.
up
0
iggvopvantoodlwin
21 years ago
With regard to the note made on results not working.
Test the database with the easy:

odbc_result_all(odbc_tables($db));

$db is obviously a connected batadase. Then start to experiment:

if(!$odbcr=odbc_tables($db,"udb","", "%", "'TABLE'"))

"udb" is the DNS - aka 'name of my ODBC database in the Windows ODBC thingamy'. In result_all the full path was shown but I just used the name I assigned; either should work.

The second parameter "" is listed by result_all as "TABLE_SCHEM" and all items were "NULL", so I have put "".

The third parameter is "%". According to result_all this col is "TABLE_NAME", so I could have put the name of one of my tables, i.e. "Address".

In my case I have an Access database setup with several tables. In ODBC I have created a link. Running the all on everything result above shows a set of system tables which I do not need to know about at this point so I look at the result and then build my new table check using the "TABLE" string as the tables I am interested in are listed as "TABLE" under their "TABLE_TYPE" column.
To Top