Welcome Guest, Not a member yet? Register   Sign In
Catch 22 using DB_Forge
#1

I wrote a database migration tool using CI's DB_Forge
It starts like this:
$this->load->dbforge();
# Create database if not exists
$this->dbforge->create_database("test"TRUE);


If my database is already created, CI could connect to it, and run this query.
However if there is no DB (which is why I need the migration tool), it will say "You have not selected a database type to connect to."

Catch 22:
To execute a "CREATE DATABASE" query, I need to have a valid database to connect to first.
To have a valid database, I need to execute "CREATE DATABASE" query

My mysql connection is as follows: (no database selected)

[
  "dsn"  => "",
  "hostname" => DB_HOSTNAME,
  "username" => DB_USERNAME,
  "password" => DB_PASSWORD,
  "port"     => DB_PORT,
  "dbdriver" => "mysqli",
  "dbprefix" => "",
  "pconnect" => TRUE,
  "db_debug" => (ENVIRONMENT !== "production"),
  "cache_on" => FALSE,
  "cachedir" => "",
  "char_set" => "utf8",
  "dbcollat" => "utf8_unicode_ci",
  "swap_pre" => "",
  "encrypt" => FALSE,
  "compress" => FALSE,
  "stricton" => FALSE,
  "failover" => [],
  "save_queries" => TRUE
]


So my questions are:
- Is this intended?
- Is there a quick fix for this?
- Is there maybe a different way to execute my query outside of this DB connection?
Reply
#2

Any solution? Possible way to work around it?
Reply
#3

The easiest way around this would be to connect to an already existing database and run your create_database() function.
Reply
#4

(10-26-2016, 10:07 AM)zknight Wrote: The easiest way around this would be to connect to an already existing database and run your create_database() function.

That means that the migration will not be self contained, and must already have a DB to connect to, meaning you have to acctually open a database manager and create a database.. I would like not to have to deal with those

Thanks anyway.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB