• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED - ]Database Forge - How to select a DB

#1
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.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.