This is pretty simple using an instance of the CDbTableSchema
class:
echo 'Name: ', $tbl->name, ' (raw: ', $tbl->rawName, ')'; echo 'Fields: ', implode(', ', $tbl->columnNames);
And so on. There are many methods and properties for this.
To get all the tables just use the CDbSchema
class here.
The CDbSchema
class has both the public tableNames
property (an array of all tbl namnes) and the tables
property containing all metadata. That is all, really.
To get to all of these instances, the following code should be sufficient:
$connection = Yii::app()->db;//get connection $dbSchema = $connection->schema; //or $connection->getSchema(); $tables = $dbSchema->getTables();//returns array of tbl schema's foreach($tables as $tbl) { echo $tbl->rawName, ':<br/>', implode(', ', $tbl->columnNames), '<br/>'; }
To create a drop-down list, you simply use the standard CHtml
object:
$options = array(); foreach($tables as $tbl) {//for example $options[$tbl->rawName] = $tbl->name; } $dropDown = CHtml::dropDownList('tables',$tables[0]->rawName, $options);
Please spend some time reading the manual , all this is there. I did not use Yii
, which is widespread, well, I did not use it at all, to be honest, but it took me only 5 minutes to fix it. Just look at the source. Each method / class / has a link to the exact line in the corresponding file!
Before asking others to figure out something for you, make some effort.