Welcome Guest, Not a member yet? Register   Sign In
Hook a database config from another system
#1

[eluser]gh0st[/eluser]
I'm wanting to "hook" database configuration files from another system so that I only have to change the db details once, in one file.

I don't want to be hacking the database config file, so I thought hooks might be able to help;

Code:
// config hooks.php
$hook['pre_system'] = array
    (
        'class'        => 'MyClass',
        'function'    => 'Myfunction',
        'filename'    => 'Myclass.php',
        'filepath'    => 'hooks'
    );

Code:
<?php
class MyClass
{
    function MyClass()
    {
    }

    function Myfunction()
    {
        include_once("../config.inc.php");

        $db['default']['hostname'] = $database_server;
        $db['default']['username'] = $database_user;
        $db['default']['password'] = $database_password;
        $db['default']['database'] = $dbase;
        $db['default']['dbdriver'] = $database_type;
        $db['default']['dbprefix'] = $table_prefix;
        $db['default']['char_set'] = $database_connection_charset;
                        
        return $db;
    }
}
?>

I've tested the details in the Myfunction and they are working -- but the DB config never changes.

I've even outputted the DB config file, ensuring that the original details do not overwrite my hook -- but nothing ever changes.

How do I get CI to hook another database config?

Thanks
#2

[eluser]pistolPete[/eluser]
[quote author="gh0st" date="1235590162"]I'm wanting to "hook" database configuration files from another system so that I only have to change the db details once, in one file.
[/quote]

Why don't you just modify ./system/application/config/database.php? It's meant to be changed according to your database settings!
#3

[eluser]gh0st[/eluser]
I thought you weren't meant to -- also I'm doing an include.

I did as you said anyway.
#4

[eluser]xwero[/eluser]
The settings in the database.php file are grouped just to allow more than one database configuration.




Theme © iAndrew 2016 - Forum software by © MyBB