PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Listing and Describing Tables

The listTables() method returns an array of strings, naming all tables in the current database.

The describeTable() method returns an associative array of metadata about a table. Specify the name of the table as a string in the first argument to this method. The second argument is optional, and names the schema in which the table exists.

The keys of the associative array returned are the column names of the table. The value corresponding to each column is also an associative array, with the following keys and values:

Table 64. Metadata Fields Returned by describeTable()

Key Type Description
SCHEMA_NAME (string) Name of the database schema in which this table exists.
TABLE_NAME (string) Name of the table to which this column belongs.
COLUMN_NAME (string) Name of the column.
COLUMN_POSITION (integer) Ordinal position of the column in the table.
DATA_TYPE (string) RDBMS name of the datatype of the column.
DEFAULT (string) Default value for the column, if any.
NULLABLE (boolean) TRUE if the column accepts SQL NULL's, FALSE if the column has a NOT NULL constraint.
LENGTH (integer) Length or size of the column as reported by the RDBMS.
SCALE (integer) Scale of SQL NUMERIC or DECIMAL type.
PRECISION (integer) Precision of SQL NUMERIC or DECIMAL type.
UNSIGNED (boolean) TRUE if an integer-based type is reported as UNSIGNED.
PRIMARY (boolean) TRUE if the column is part of the primary key of this table.
PRIMARY_POSITION (integer) Ordinal position (1-based) of the column in the primary key.
IDENTITY (boolean) TRUE if the column uses an auto-generated value.

How the IDENTITY Metadata Field Relates to Specific RDBMSs

The IDENTITY metadata field was chosen as an 'idiomatic' term to represent a relation to surrogate keys. This field can be commonly known by the following values:-

  • IDENTITY - DB2, MSSQL

  • AUTO_INCREMENT - MySQL/MariaDB

  • SERIAL - PostgreSQL

  • SEQUENCE - Oracle

If no table exists matching the table name and optional schema name specified, then describeTable() returns an empty array.

Zend Framework