views:

25

answers:

2

Hello,

Can you help me how to use class defined in CakePHP's /config/database.php file, for my custom scripts? I need to use defined array for db connection.

Tnx in adv!

A: 

It sounds like you're looking for something similar to Rails' migrations, i.e. scripts that run within the context of the framework. There have been efforts to create such a thing (see Joel Moss' article in the Bakery).

What I tend to do is to keep a set of DDL scripts in a _meta/ directory of my project. I execute these directly on the database so they have no need to read info from database.php. If you're set on using Cake's runtime context, my way won't help you, but maybe Joel's will.

Rob Wilkerson
+1  A: 

There is nothing magic about this class. It works the same as any other PHP class.

<?php

include("path/to/cake/config/database.php");
$db = new DATABASE_CONFIG;

echo $db->default['login'];
echo $db->default['password'];
echo $db->default['database'];

?>

Now you can reference the variables like you would with any other class.

cdburgess