Listing Tables name in CakePHP

We can use the following code in listing the tables name or checking the existence of a table in database using cakePHP.

In CakePHP 2.X versions.

  1. Add ” App::uses(‘ConnectionManager’, ‘Model’); ” in the controller in which you want to process the list. You have to add this code before defining the class controller.
  2. ” $tables= ConnectionManager::getDataSource(‘default’)->listSources(); “. Now $tables will be the list of exist tables in database.

In CakePHP 3.X versions.

  1. Add ” use Cake\Datasource\ConnectionManager;  ” in the controller in which you want to process the list. You have to add this code before defining the class controller.
  2. ” $tables = ConnectionManager::get(‘default’)->schemaCollection()->listTables(); “. Now $tables will be the list of exist tables in database.