Post by DBI » Fri Oct 30, 2020 8:33 am

I've having trouble creating a new table as part of a modification.

My ocmod.zip installation works fine, OCMOD modifications are run, files are moved to the correct directories. However my query to create a new database table doesn't seem to be running.

My understanding is that the way to do this is to put the query in the controller, located in: admin/controller/extension/catagory/mycontroller.php like so:

Code: Select all

class ControllerExtensionMyController extends Controller
{
	private $error = array();

	public function install()
	{
        $this->db->query("CREATE TABLE IF NOT EXISTS ... ;");
        }
However the table is not created and nothing shows up in the error log. Any thoughts about what might be happening?

DBI
New member

Posts

Joined
Tue Oct 14, 2014 10:58 am

Post by sw!tch » Fri Oct 30, 2020 9:08 am

You can create a module and then hook the install / uninstall methods.

ex:

Code: Select all

class ControllerExtensionModuleMyModule extends Controller {

    public function index() {}

    public function install() {}

    public function uninstall() {}
}

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by straightlight » Fri Oct 30, 2020 7:23 pm

Since the query is already in the install() method, ensure your table permissions are activated from your hosting database console prior to launch those queries - especially during magic method detections.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DBI » Sat Oct 31, 2020 5:37 am

The database user has table creation permissions.

DBI
New member

Posts

Joined
Tue Oct 14, 2014 10:58 am

Post by straightlight » Sat Oct 31, 2020 6:07 am

The query does state IF NOT EXISTS . Ensure to check on your database in case the table has already been created. In the uninstall() method, the DROP TABLE should be used for testing purposes (new table). Which way you decide to do it, however, always make a backup first.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DBI » Sat Oct 31, 2020 6:32 am

I think you're asking if the database is there, but the entire problem is that it isn't!

DBI
New member

Posts

Joined
Tue Oct 14, 2014 10:58 am

Post by sw!tch » Sat Oct 31, 2020 6:59 am

Has nothing to do with your query, you have to call the install method, either via your controller or via the module installer.

If you read my reply, you can easily resolve the issue by using a module, which calls install() on activation.

Otherwise just work alternative means to run your query.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Who is online

Users browsing this forum: No registered users and 167 guests