5.5.16

odbc_tables

(PHP 4, PHP 5)

odbc_tablesObtener la lista de los nombres de las tablas almacenados en una fuente de datos específica

Descripción

resource odbc_tables ( resource $connection_id [, string $qualifier [, string $owner [, string $name [, string $types ]]]] )

Lista todas las tablas del rango solicitado.

Para soportar la enumeración de cualificadores, propietarios y tipos de tabla, están disponibles las siguientes semánticas especiales para qualifier, owner, name, y table_type:

  • Si qualifier es un único carácter de porcentaje (%) y owner y name son cadenas vacías, el conjunto de resultados contendrá una lista de cualificadores válidos para la fuente de datos. (Todas las columnas excepto la columna TABLE_QUALIFIER contienen NULLs.)
  • Si owner es un único carácter de porcentaje (%) y qualifier y name son cadenas vacías, el conjunto de resultados contendrá una lista de propietarios válidos para la fuente de datos. (Todas las columnas excepto la columna TABLE_OWNER contienen NULLs.)
  • Si table_type es un único carácter de porcentaje (%) y qualifier, owner y name son cadenas vacías, el conjunto de resultados contendrá una lista de tipos de tablas válidos para la fuente de datos. (Todas las columnas excepto la conlumna TABLE_TYPE contienen NULLs.)

Parámetros

connection_id

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

qualifier

El cualificador.

owner

El propietario. Acepta patrones de búsqueda ('%' para comparar cero o más caracteres y '_' para comparar un único carácter).

name

El nombre. Acepta patrones de búsqueda ('%' para comparar cero o más caracteres y '_' para comparar un único carácter).

types

Si table_type no es una cadena vacía debe contener una lista de valores serparados por comas para los tipos que son de interés; cada valor puede ser encerrado en comillas simples (') o sin comillas. Por ejemplo, "'TABLE','VIEW'" o "TABLE, VIEW". Si la fuente de datos no soporta un tipo de tabla especificado, odbc_tables() no devolverá ningún resultado para ese tipo.

Valores devueltos

Devuelve un identificador de resultado ODBC que contiene la información o FALSE en caso de error.

El conjunto de resultados tiene las siguientes columnas:

  • TABLE_QUALIFIER
  • TABLE_OWNER
  • TABLE_NAME
  • TABLE_TYPE
  • REMARKS

El conjunto de resultados está ordenado por TABLE_TYPE, TABLE_QUALIFIER, TABLE_OWNER y TABLE_NAME.

Ver también

add a note add a note

User Contributed Notes 6 notes

up
0
narcomweb at wanadoo dot fr
8 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
10 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.
up
0
kthejoker at nospam dot hotmail dot com
11 years ago
A bit of an extension on the previous posts:

I had a whale of a time trying to make this command work .. the parameters were hard to decipher, and frequently my Apache module would just crash and burn when I tried to run it. I FINALLY figured out what was wrong ...

< -- assuming $conn is your odbc_connect --->

$tablelist=odbc_tables($conn);
$tablelist=odbc_result_all($tablelist);

simply doesn't work. I don't understand the exact logistics of it, but the only way I could get it to post the results was this:

$tablelist=odbc_result_all(odbc_tables($conn));

From there it was rather simple to add in parameters that fished out the results I wanted.

To repeat again: I do not understand why the 2nd method works and the 1st one does not. However, having struggled mightily with this function for almost 24 hours, posting this solution has proven to be greatly satisfying.
up
0
liquidicee at hotmail dot com
13 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
fmk at swwwing dot com
13 years ago
use odbc_tables($con, "%") to get a list of all available catalogs (databases).

use odbc_tables($con, "", "%") to get a list of all schemas available.

use odbc_tables($con, "", "", "", "%") to get a list of all table types available.

use odbc_tables($con, "my catalog", "my schema", "%", "'TABLE', 'VIEW'") to get a list of all tables available.

using odbc_tables($con, "%", "%", "%", "%") will return an empty array !

Before PHP 4.0.3 uou could use this function with 1 or 5 prarms. From 4.0.3 the function matches the documentation.
up
-1
pmains at ux dot com
9 years ago
This probably works for a variety of formats, but if you want a list of *just* the table names from an SQL dsn source (I'm using MSSQL), here's the code.

<?php

# ... assign $dsn, $uid, & $pwd ...

$dbh = odbc_connect($dsn, $uid, $pwd);

   
$result = odbc_tables($dbh);
   
   
$tables = array();
    while (
odbc_fetch_row($result))
       
array_push($tables, odbc_result($result, "TABLE_NAME") );
   
    foreach(
$tables as $t ) {
        echo
"$t\n";   
    }

?>
To Top