Resession

A small lightweight script that can manage and manipulate Session data.

Retrieving tables within your Cake database

Saturday, January 16th 2010, 1:04am
Topics: Tutorials, CakePHP
Tags: Manager, Database, Table, Show, List, Sources, Connection
Comments: 2
Permalink - Tinylink

I have been working lately on adding an installation process to my forum plugin. For this process I needed a way to retrieve a list of tables within a selected database, to make sure there are no table name conflicts. After asking the question on Twitter, I got the answer thanks to @pierremartin and @mark_story (of course!). You simply use the ConnectionManager class.

$db = ConnectionManager::getDataSource('default');
$tables = $db->listSources();


Very handy, and a lot easier then writing a custom query with execute().
Related Entries:

2 Comments

10 / 2 = ?
Allowed: [code] [b] [i] [u]
  • Robust Solution
    Jan 16th 2010, 14:45
    1 nice tip.

    I always use it when I want to implement my old (non-CakePHP) database class singleton in CakePHP
  • Brendon Kozlowski
    mysiteonline.org
    Jan 19th 2010, 08:55
    2 Awesome find, Miles. I'll be sure to use this at some point. Thanks for sharing!