1

I need to user show table query in cakephp i have tried manually write SHOW table status FROM DATABASE like 'table_name' but my concern is when i lived this site my database name change accordingly and i do not want to change it manually.

i also tried below code but i could not find my table detail.

$db =& ConnectionManager::getDataSource('default');
$modelname = "service_requests";
$query = $db->describe($modelname);

and i expect that my query would return something like below.

[TABLES] => Array
(
     [Name] => service_requests
     [Engine] => MyISAM
     [Version] => 10
     [Row_format] => Dynamic
     [Rows] => 201
     [Avg_row_length] => 478
     [Data_length] => 96536
     [Max_data_length] => 281474976710655
     [Index_length] => 4096
     [Data_free] => 400
     [Auto_increment] => 202
     [Create_time] => 2012-12-13 17:10:16
     [Update_time] => 2012-12-18 10:27:34
     [Check_time] => 
     [Collation] => utf8_general_ci
     [Checksum] => 
     [Create_options] => 
     [Comment] => 
)

Thanks you very much.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
  • `=&` is bad in this instance and should throw a warning error - objects are always references. As far as your question - you have to specify the database name in your configuration settings so grab it from there to compose the query instead of hard coding it. – prodigitalson Dec 18 '12 at 05:05
  • Fatal error: Cannot pass parameter 1 by reference in this is the error i get – Dipesh Parmar Dec 18 '12 at 05:06
  • Use: `$db = ConnectionManager::getDataSource('default');` – prodigitalson Dec 18 '12 at 05:12
  • already did but same only table is described not table updatetime and etc as mentioned in question.i want array of table creation and update array. – Dipesh Parmar Dec 18 '12 at 05:13
  • Refer: http://stackoverflow.com/questions/3647065/how-can-i-see-cakephps-sql-dump-in-the-controller – shasi kanth Dec 18 '12 at 05:19

1 Answers1

1

Ohhh Damn that was so easy and i was going too rough on it.

following code worked for me like charm.

i am sharing this code so it will help others.

$database_name = $this->ServiceRequest->getDataSource()->config['database'];

$query = $this->ServiceRequest->query(
             "show table status from 
                 " . $database_name . " 
                like '" . $this->tableName . "'");
pr($query);

and i get the result what i wanted.

Thanks for help @dskanth and @prodigitalson.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90