Thursday, March 17, 2022

[FIXED] cakephp get schema for list of tables

Issue

Is there an easy way in cakephp to get an array of tables schema for a list of specific tables? For example, i want a table schema for table a, b, d, f, and z; Also, is there a way to get a schema array of all the tables?


Solution

Get a datasource, by:

$db =& ConnectionManager::getDataSource('default');

or

$db =& $this->User->getDataSource(); // or any other model 

Then you can get all the tables by calling:

$db->listSources()

And get the schema for a table, say "products"

$db->describe('products');

However, passing a string to describe is only in CakePHP 2.0, 1.3 requires a model object.



Answered By - ori

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.