Table of Contents
Sometimes, you don't want to fetch data from a database table. Instead, you want to fetch data about a database table. DbMeta is our answer to this problem. Using this API, you can easily retrieve the columns or the primary key of a table and much more. Useful examples include writing automatically various queries or writing a differential tool to compare two different versions of a table in a database.
All the database drivers and their PDO counterparts have DbMeta support. They all provide access to the tables, columns and primary and foreign keys of the database. The PostgreSQL and Oracle ones also provide methods to retrieve data about database schemas.
This documentation comes in the form of a function reference of everything you can do using DbMeta. The usage is rather straightforward and the examples should explain a lot.
To query the database you must use the DbMeta object.
To retrieve an instance of this object for your database,
simply call the method meta of your database driver.
<?php // If you are using the application module $oMeta = weeApp()->db->meta(); // Otherwise $oMeta = $oDb->meta();
Every database object represented in DbMeta is an instance of weeDbMetaObject.
A database object can be a schema, a table, a column, a primary key, a foreign key, a sequence... and much more depending on the database you use.
Every database object have a name.
You can retrieve this name by using the name method.
<?php
$sName = $o->name();
Alternatively, you can also directly obtain the quoted name of the database object by using the quotedName method.
The name returned will be quoted using the escapeIdent method of the associated driver and will thus be safe to use in a query.
<?php
$sQuotedName = $o->quotedName();