Dynamic database creation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Dynamic database creation (/showthread.php?tid=37747) |
Dynamic database creation - El Forum - 01-19-2011 [eluser]crazypolecat[/eluser] Hello, CodeIgniter's Database library is powerful and I like its ease of use a lot, but for a particular project I need to dynamically create new databases. Getting it to work is no problem. I use mysql_connect and mysql_query, but I wonder if this is the best approach in CodeIgniter? I assume that the Database class cannot be used for this kind of tasks. Thanks. Dynamic database creation - El Forum - 01-19-2011 [eluser]bl00dshooter[/eluser] Use the database forge class: http://ellislab.com/codeigniter/user-guide/database/forge.html Dynamic database creation - El Forum - 01-19-2011 [eluser]crazypolecat[/eluser] That's exactly what I needed. Thanks! Dynamic database creation - El Forum - 01-19-2011 [eluser]crazypolecat[/eluser] I noticed to issues when reading the user guide on dbforge. When you create a table with dbforge, how does it know to which table it should add the table? Also, you can add a second parameter when creating a table to see if the table already exists, but this option is not available for creating a database. This seems odd or am I overlooking something? Thanks. Dynamic database creation - El Forum - 01-19-2011 [eluser]cideveloper[/eluser] This code solves both your problems. Code: $this->load->dbforge(); Dynamic database creation - El Forum - 01-20-2011 [eluser]crazypolecat[/eluser] This is indeed what I was looking for. I didn't know about the dot-notation in the create_table method. That's a handy feature! Thanks a lot. |