PHP 7.4.0RC4 Released!


(PHP 4, PHP 5, PHP 7)

odbc_tablesListe les tables d'une source


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

Liste les tables d'une source.

Pour supporter les énumérations de qualificateurs propriétaires et types de table, la sémantique suivante pour les paramètres qualifier, owner, name et table_type est disponible :

  • Si qualifier est un signe de pourcentage (%), et owner et name sont des chaînes vides, alors le résultat contient la liste des qualifiés valides pour la source (toutes les colonnes hormis TABLE_QUALIFIER contiennent NULL).
  • Si owner est un signe de pourcentage (%), et qualifier et name sont des chaînes vides, alors le résultat contient la liste des propriétaires de la source (toutes les colonnes hormis TABLE_OWNER contiennent NULL).
  • Si table_type est un signe de pourcentage (%), et qualifier, owner et name sont des chaînes vides, alors le résultat contient la liste des types de tables de la source (toutes les colonnes hormis TABLE_TYPE contiennent NULL).

Liste de paramètres


L'identifiant de connexion ODBC, voir la documentation de la fonction odbc_connect() pour plus de détails.


Le qualifieur.


Le propriétaire. Accepte des masques de recherche ('%' pour remplacer zéro ou plus caractères, et '_' pour n'en remplacer qu'un seul).


Le nom. Accepte des masques de recherche ('%' pour remplacer zéro ou plus caractères, et '_' pour n'en remplacer qu'un seul).


Si table_type n'est pas une chaîne vide, il doit contenir une liste de valeurs, séparées par des virgules, qui représentent les types recherchés. Chaque valeur peut être insérée entre guillemets simples ('), ou sans guillemets. Par exemple, "'TABLE','VIEW'" ou "TABLE, VIEW". Si la source de données ne supporte pas un type de table donné, odbc_tables() ne retournera aucun résultat pour ce type.

Valeurs de retour

Retourne un identifiant de résultat ODBC contenant les informations ou FALSE si une erreur survient.

Le résultat contient les colonnes suivantes :


Le résultat est ordonné grâce aux options TABLE_TYPE, TABLE_QUALIFIER, TABLE_OWNER et TABLE_NAME.

Voir aussi

add a note add a note

User Contributed Notes 5 notes

kthejoker at nospam dot hotmail dot com
16 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 --->


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:


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.
15 years ago
With regard to the note made on results not working.
Test the database with the easy:


$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.
narcomweb at wanadoo dot fr
13 years ago
Here a Code for listing Table names
= odbc_connect($dsn, $user, $pwd);

$result = odbc_tables($dbh);

$tables = array();
   while (

You don't have views or System tables with.
Only simple tables in your database.
liquidicee at hotmail dot com
18 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

= odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (
odbc_fetch_row($tablelist)) {
if (
odbc_result($tablelist, 4) == "TABLE")
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.

= odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (
odbc_fetch_row($tablelist)) {

hopefully this will help some people.. i have alot more to add about this but no time :(
so again hope this helps.
pmains at ux dot com
14 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.


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

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

$result = odbc_tables($dbh);
$tables = array();
    while (
array_push($tables, odbc_result($result, "TABLE_NAME") );
$tables as $t ) {

To Top