Most Web sites today have some aspects which are driven by a database. To empower developers with an easy to use database scheme, InterJinn provides a centralized configuration variable where you may define the configuration for any databases you will use. Having done so will make it extremely easy to access databases in your components since you can refer to the database via the key that you provide in the configuration array. Moreover, if any of the configuration settings for the database should change then you will only need to update one location. You can read about how to actually use your databases in the main Database Documentation.
This configuration variable holds all of your database
access settings. Currently the array has a format of key and value. The key denotes the name that will be used in your code to select
the given database, and the value denotes
either the actual configuration settings or the key of another entry in the
same array which defines the configuration. By setting the value to reference another entry in the structure you can
easily create aliases to the same database.
$GLOBALS['interJinn']['databases'] = array
(
'interjinn' => array
(
'host' => '',
'user' => 'interjinn',
'password' => 'aWeSoMe',
'db' => 'interjinn'
),
'newsfeed' => array
(
'host' => 'www.fakenewsfeed.com',
'user' => 'interjinn',
'password' => 'aWeSoMeNeWs',
'db' => 'interjinn'
),
'jinn' => 'interjinn',
'news' => 'newsfeed',
'default' => 'interjinn'
);
Currently there are only five configuration settings
available for the default MySQL database service - host, port, user, password, and db. The purpose of each of these fields should be obvious and
so an explanation is omitted; any unrecognized fields will be ignored and so
compatibility is maintained with other database services that may require more
fields to be set. Please note that you MUST define a default alias. The default is
used by the core services to determine where their data is stored. For
instance if you are using database properties then the Property System uses the default
alias to retrieve component properties from the associated database.
Since it would be fairly limitting to only have one database service available to developers, and because it would be a lengthy process for me to write a separate database service for every database type out there (Oracle, PostgreSQL, Mini SQL, etc.), I have included an optional second PEAR::DB wrapper database service which can be configured as follows:
Add the following line to the services configuration array
($GLOBALS['interJinn']['services']) as
described in the services configuration documentation:
'PearDbManager' =>
'Core/libraries/database/pearDb/pearDbManager.inc',
getService() or getLibrary()
method is called. Next you need to add the following line to the services
aliases array ($GLOBALS['interJinn']['serviceAliases']).
'dbManager' => 'PearDbManager',
$GLOBALS['interJinn']['databases'] = array
(
'interjinn' => array
(
'type' => 'mysql', // Field is mandatory.
'dbsyntax' => '',
'user' => 'interjinn',
'password' => 'aWeSoMe',
'protocol' => '',
'port' => '',
'host' => '',
'db' => 'interjinn'
),
'default' => 'interjinn'
);
PEAR DB::connect() method. You do not need to include fields which
are empty, they are only listed here so you can have an overview of what
fields are available.