How to use Forge Class to create a database schema? |
I'm using CodeIgniter 3.1.0 to develop an app. In order to improve installation, I've written an Install_Controller, and an Install_Model.
I want to use Database Forge class to manage the database schema, but it's not very clear in user guide and nothing on Google helps. I need to use $this->dbforge->create_database, because the user knows nothing about database, so all he will do is MySQL "Next, next, install" and then run a Windows batch file that run PHP as web server, so from Chrome he can use URL to install the app. User guide says: In order to initialize the Forge class, your database driver must already be running, since the forge class relies on it. So I have setup the config/database.php with user, pwd, dbname and so on... Even because I need it to use in app. That's working fine in app. After I delete my database to start over from a fresh install and try to load the Install URL, give me the error: Message: mysqli::real_connect(): (HY000/1049): Unknown database 'test' So, how can I use Forge Class to create database schema, if I need to have it first? Some code... Code: $db['default'] = array( I made a very dirty workaround, I hope someone give me a nice answer... 1. Remove database from autoloader. 2. Use multiple databases, the default one is the same, but I created a second one having empty database name. 3. Use the second database with Forge Class, instead of the default until create schema, then I back to the default to create tables. 4. Load manually the default database in others Controllers |
Welcome Guest, Not a member yet? Register Sign In |