Welcome Guest, Not a member yet? Register   Sign In
DB Forge with DSN Conn
#1

[eluser]dave80[/eluser]
Would anyone know is this is possible at all?

class Bla bla extends Controller{
.......
..
$dsn = 'mysql://username:password@localhost/databse_other_then_whats_in_config';
$DB1 = $this->load->database($dsn, TRUE, TRUE);

$fields = array(
'users' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
);

$DB1->dbforge->add_field($fields);
$DB1->dbforge->create_table('table_name', TRUE);

Im assuming dbforge functions only works with $this->db
#2

[eluser]dave80[/eluser]
To add on my previous post, I think the $this->dbforge->create_database() function should be removed. As I can not see how you can access the database this function just created. Hence thats why I am trying to get it to work using the DSN connection. All I want to do is create a database and fill it up with tables.

Should I be using an external script for this whole procedure, or am I completely mistaken about the whole dbforge subject? Smile
#3

[eluser]TheFuzzy0ne[/eluser]
Your class name should not contain a whitespace. (just kidding). Tongue

Also not sure what purpose the third parameter serves in $this->load->database().

I don't see why it shouldn't work like that.
Code:
$dsn = 'mysql://username:password@localhost/table';
$DB1 = $this->load->database($dsn, TRUE, TRUE); // Load the database.

$fields = array(
    'users' => array(
        'type' => 'VARCHAR',
        'constraint' => '100',
        ),
    );
      
$this->dbforge->db =& $DB1; // This line should set the db class for the dbforge instance.
$this->dbforge->add_field($fields);
$this->dbforge->create_table('table_name', TRUE);
The code above is untested.
#4

[eluser]dave80[/eluser]
Also not sure what purpose the third parameter serves in $this->load->database().

Originaly when I started off, any DSN connection I made, would not work. IT would basicaly default to the default database in config.

So I tried http://ellislab.com/forums/viewthread/88058/ (last thread)

and the manual connection would finaly work. However now I have removed auto load database, and it works with out the third parameter, as per documentation.




Theme © iAndrew 2016 - Forum software by © MyBB