Create tables Opencart

Please LogIn to Reply!

Post By: guest | 01-19-2013 07:57 Reply

Question

Hi guys I'm pretty new to all of this. I'm using DIY module builder and it all seems quite straight forward though I would like to create a new table.

In the example is this line of code :
public function createModuleTables() {
$query = $this->db->query("CREATE TABLE IF NOT EXISTS " . DB_PREFIX . "blog (blog_id INT(11) AUTO_INCREMENT, sort_order INT(3), status INT(1), date DATE, PRIMARY KEY (blog_id))");
$query = $this->db->query("CREATE TABLE IF NOT EXISTS " . DB_PREFIX . "blog_description (blog_id INT(11), language_id INT(11), title VARCHAR(64), description text, PRIMARY KEY (blog_id, language_id))");
$query = $this->db->query("CREATE TABLE IF NOT EXISTS " . DB_PREFIX . "blog_to_store (blog_id INT(11), store_id INT(11), PRIMARY KEY (blog_id, store_id))");
}

but where does this have to be called in order for the tables to be created?

Many thanks

Answers

Depends on where you want it to be created. I usually create my tables on module install, i.e. install() function in admin/controller/module/modulename.php. It gets executed when you install the module via back-end

affect wrote:Depends on where you want it to be created. I usually create my tables on module install, i.e. install() function in admin/controller/module/modulename.php. It gets executed when you install the module via back-end

agreed.

Reply Or Comment!
Please LogIn to Reply!