Welcome Guest, Not a member yet? Register   Sign In
Creating New Databases and Tables

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:

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.

I'm wondering if you have to use the following to create tables in your database

$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.


Hmm. Okay, I tried this:
// Create database
$db = $_POST['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".

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


Theme © iAndrew 2016 - Forum software by © MyBB