Catch 22 using DB_Forge - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: Catch 22 using DB_Forge (/showthread.php?tid=66462) |
Catch 22 using DB_Forge - AmitMY - 10-24-2016 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? RE: Catch 22 using DB_Forge - AmitMY - 10-26-2016 Any solution? Possible way to work around it? RE: Catch 22 using DB_Forge - zknight - 10-26-2016 The easiest way around this would be to connect to an already existing database and run your create_database() function. RE: Catch 22 using DB_Forge - AmitMY - 10-26-2016 (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. |