• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating New Databases and Tables

#1
[eluser]BrandonDurham[/eluser]
I'm trying to create a new database on the fly and drop a couple of tables into it and I'm having some problems. CI doesn't see to have a way to add tables to a newly-created database via its CI Database functions. I can easily create the new database with:
Code:
$this->dbutil->create_database($db);

But I have no idea how to add tables to that newly-created database. I saw in this thread where Shadowhand mentions using str_replace, but I'm not sure what they mean.

Suggestions? I appreciate any help.

Thank you.

#2
[eluser]KJTED[/eluser]
I'm wondering if you have to use the following to create tables in your database

Code:
$query = $this->db->query("SOME QUERY");

This isn't something I've had to do and I'm fairly new to CI also but it's worth a try?

Check out the database library help pages in the documentation and look at the Custom Function Calls section.

KJ

#3
[eluser]BrandonDurham[/eluser]
Hmm. Okay, I tried this:
Code:
// Create database
$db = $_POST['db'];
$this->dbutil->create_database($db);

// Connect to the new database
$newdb = $this->load->database($db, TRUE);

... and no dice. I get the error "You have specified an invalid database connection group: Test_Coupon_Site_3".

#4
[eluser]KJTED[/eluser]
I don't think you are passing a database connection, it looks like it's just a string perhaps.


I think you need to set up a connection properly

http://ellislab.com/codeigniter/user-gui...cting.html


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.