weeDbMeta and weeDbMetaSchema allow you to retrieve a list of their associated tables.
A table is an instance of weeDbMetaTable and
contains methods to fetch information about the table or database objects it contains.
You can use the tables method to retrieve a list of tables.
You will receive an array of weeDbMetaTable objects
that you can then use to get information about the table.
The tables are returned ordered by name.
<?php $aTables = $oDb->meta()->tables();
The exact meaning of the tables method may vary when the underlying RDBMS also supports schemas.
For example, the PostgreSQL DbMeta object's tables method only returns the visible tables,
based on the schema search path.
You may also want to fetch all the tables from a specific schema, if the database driver you use support them. The schema object allows you to retrieve all the tables associated with itself.
<?php $oSchema = $oDb->meta()->schema('some_schema')->tables();
Additionally, may you require nothing more, you can obtain an array containing only the names
of these tables through the tablesNames method.
<?php
$aTablesNames = $o->tablesNames();
To check for a table existence, you can use the tableExists method.
You can use this method both with the DbMeta object or the schema object.
<?php // Check if the table exists in the database $bTableExists = $oDb->meta()->tableExists('some_table'); // Check if the table exists in a given schema $bTableExists = $oDb->meta()->schema('some_schema')->tableExists('some_table');
To fetch a table, use the method of the same name.
The table method is available both on the DbMeta and the schema objects.
The returned object is an instance of weeDbMetaTable.
If the table does not exist in the database or the schema, an UnexpectedValueException is thrown.
<?php
try {
$oTable = $oDb->meta()->table('some_table');
} catch (UnexpectedValueException $e) {
// The table "some_table" does not exist in the database
}