Welcome Guest, Not a member yet? Register   Sign In
Create database name on the fly
#1

[eluser]columbus13[/eluser]
Hello all,

I have a requirement whereby my SQL database name carries additional information (id, event name, etc.). I cannot have it hard-coded in the config file and would have to generate it programmatically. i looked through the documentation, but did not find any way to programmatically generate the $db[][] configs in database.php. I am pretty sure this should be possible, but I am not enough of a CI or PHP expert to figure this out without much struggle. Can someone help?

best,
c
#2

[eluser]trumpetnl[/eluser]
If you use the full database.table format name it can work. I tried it on my MySQL database.

i created 3 databases
- oeps1
-> naw(recid(int), name(varchar(60))
- oeps2
-> adressen(recid(int), woonplaats(varchar(60))
- oeps3
-> straten(recid(int), straatnaam(varchar(60))

in my database.php i configured my dbuser and password, database is left empty


Then i used this controller:
Code:
<?php
class Dbproeftuin extends Controller {
    function dbproeftuin() {
        parent::Controller();
    }

    function index() {
        $query1 = $this->db->get('oeps1.naw');
        $query2 = $this->db->get('oeps2.adressen');
        $query3 = $this->db->get('oeps3.straten');
        $naw = $query1->row();
        $adressen = $query2->row();
        $straten = $query3->row();
        echo 'Recid : ' . $naw->recid . br(1);
        echo 'Naam  : ' . $naw->name . br(1);
        echo 'Straat: ' . $straten->straatnaam . br(1);
        echo 'Plaats: ' . $adressen->woonplaats . br(1);
    }
}

Only thing to consider is, you need a database-user that can access all database you want to use.

I hope this helps you, it was fun to explore :-)

//
#3

[eluser]columbus13[/eluser]
Trumpetni - Thanks much.
#4

[eluser]trumpetnl[/eluser]
hi Columbus,

your welcome

//T




Theme © iAndrew 2016 - Forum software by © MyBB