How to get Column Name With Zend DB

2020-06-12 02:55发布

问题:

How to get Column Name With Zend DB

回答1:

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

$cols = $table->info(Zend_Db_Table_Abstract::COLS); 


回答2:

$metadata = $db->describeTable($tableName);
$columnNames = array_keys($metadata);

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



回答3:

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



回答4:

You could use the describeTable method



回答5:

I like this way:

$table->info('cols');