Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: Accessing database.php values

Tags:

php

cakephp

I need to retrieve values from CakePHP's config file database.php from one of my controllers.

I'm maintaining an ex-employee's code, so I'm not positive how much of this adheres to default structures. I'm hoping this is fairly straightforward, but I can't seem to Google the right info.

File: app/config/database.php

class DATABASE_CONFIG
{
    var $db1 =
        array('driver' => 'mysqli',
              'connect' => 'mysql_connect',
              'host' => 'localhost',
              'login' => 'username',
              'password' => 'password',
              'database' => 'schema',
              'prefix' => '');
}

File: app/controllers/my_controller.php

// here is where I need to retrieve
// the database login and password values

What syntax can I use here? Is it even possible to retrieve these values, or are they only accessible to the guts of the CakePHP framework?

like image 637
DreadPirateShawn Avatar asked Jul 27 '09 07:07

DreadPirateShawn


1 Answers

$fields = get_class_vars('DATABASE_CONFIG')

echo $fields['db1']['login'];
like image 179
RaYell Avatar answered Sep 21 '22 19:09

RaYell