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?