Zend Framework getting table meta data infromation

27 Nov

Yesterday I was checking how can we get table meta data information, like table name, columns names etc, and was surprised to see that how easy It is to have these information using Zend_Db component of Zend Framework.
Let us see how we can get table name and columns names using a simple example.
Consider you have a table with name “company” with following information.

• Id
• Company_name
• Address
• Phone

First create a model class as

class Company extends Zend_Db_Table
protected $_name= “company”;


Next in your controller/action.
Create an instance of your newly created class as

$company = new Company();

And now get meta data information as

$info = $company->info();

This will return an array of information.
You can check the information return by simply writing


The will show the entire information return by info().
If you want to have column names simple write

foreach($info[“cols”] as $col) {
echo $col . “\t”;


This will show the name of the colums of your table.
That’s it. Enjoy.


One Response to “Zend Framework getting table meta data infromation”

  1. burntblark April 11, 2011 at 6:04 pm #

    Nice! I have been looking for this. Thanks :). What happens when you want to get just the column names of queried fields. As in, when you query for just a subset of columns is it possible to get just the column names from the metadata

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: