How to get Column Name With Zend DB
Asked Answered
O

5

11

How to get Column Name With Zend DB

Officialdom answered 2/4, 2009 at 8:18 Comment(1)
Perhaps you should describe a little bit what you're trying to do... Apikot's answer is a starting point though.Rayborn
S
28

This is the correct answer, the older answers are wrong or outdated:

$cols = $table->info(Zend_Db_Table_Abstract::COLS); 
Sugary answered 21/9, 2009 at 9:20 Comment(1)
rewrote your intro-text since SO doesn't know 'bumping' and questions/answers are not considered old. in fact SO is a wiki and updating it is one of the best things you can do! +1Brackish
C
8
$metadata = $db->describeTable($tableName);
$columnNames = array_keys($metadata);

http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.list-describe

Chronogram answered 2/4, 2009 at 8:29 Comment(2)
That's not really 100% correct as $metadata is an associative array ('column_name' => array()) of associative arrays (one for each column of the table).Rayborn
add schame's name to $db->describeTable($tableName, $schema); , i just had an error using oracle which takes old column names if i had changed them and had to specify the schema for it to return right column namesZasuwa
R
2

Previous answer applies only to version < 2.
For current version of ZF (2.2) use:

$table = new Zend\Db\TableGateway\TableGateway('table', $Dbadapter, new Zend\Db\TableGateway\Feature\MetadataFeature());
$columns = $table->getColumns();

http://framework.zend.com/manual/2.2/en/modules/zend.db.table-gateway.html#tablegateway-features http://framework.zend.com/manual/2.2/en/modules/zend.db.metadata.html

Ruscio answered 22/5, 2013 at 10:57 Comment(0)
L
0

You could use the describeTable method

Limnology answered 2/4, 2009 at 8:23 Comment(0)
H
0

I like this way:

$table->info('cols');
Halle answered 23/5, 2013 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.