Friday, January 3, 2014

Yii and Oracle

Getting Table Structure

This is how to get name, type and size of all the columns of table, owner_name.mytable.
// dbOracle must have been defined in configurations
$remote_db = Yii::app()->dbOracle;

$stru = $remote_db->createCommand()
  ->from('ALL_TAB_COLS')
  ->where("TABLE_NAME = 'mytable' AND OWNER = 'owner_name'")
  ->queryAll();

$col_info = array();

foreach ($stru as $_col_meta)
{
  $_info = new stdClass();

  $_info->name = $_col_meta['column_name'];
  $_info->type = $_col_meta['data_type'];
  $_info->size = $_col_meta['data_length'];

  $col_info[] = $_info;
}

print_r($col_info);