Welcome Guest, Not a member yet? Register   Sign In
[SOLVED - ]Database Forge - How to select a DB
#1

(This post was last modified: 12-14-2019, 12:39 PM by reszko.)

Hi.

When I use $forge->createDatabase('databaseName'); to create a database, it works successfully, but, when I use $forge->createTable('tableName') it adds this table to my database that is configured in /app/config/database.php.

How can I work with the recent created database?

I tried to find a $forge->selectDB() method or something like this but I didn't get success.

Thank you.
My english is a work in progress.
Fabio
Reply
#2

(12-12-2019, 04:30 PM)reszko Wrote: Hi.

When I use $forge->createDatabase('databaseName'); to create a database, it works successfully, but, when I use $forge->createTable('tableName') it adds this table to my database that is configured in /app/config/database.php.

How can I work with the recent created database?

I tried to find a $forge->selectDB() method or something like this but I didn't get success.

Thank you.
My english is a work in progress.
Fabio

Well, I don't know if this is the correct way, but I found a way to select the database I want to use.
You need to get the db connection instance, like this:

PHP Code:
$db db_connect();
//Then you do:
$db->setDatabase('newDatabase'); 

The setDatabase method uses the current database connection configs but changes only the database name.
If you need to connect to another database address, then you should create a new database group inside config/Database.php

And after this, all database forge commands will affect the new database selected.
It worked for me.

I would appreciete if someone tell me if I am doing something wrong.

Thank you all.
Fabio
Reply
#3

You're doing it correctly.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB