How to remove all rows from a database table?
Permalink
I'm stuck on how to actually drop or even remove rows from a database table when a block is uninstalled.
Here's my current method that I'm using.
I've also tried these two way without success:
None of these methods seem to work. What am I doing wrong here? All I want is to clean up the database when my block is removed.
Here's my current method that I'm using.
function delete(){ $db = Loader::db(); $db->query("DELETE * FROM tableName"); parent::delete(); }
I've also tried these two way without success:
function delete(){ $db = Loader::db(); $db->query("DROP TABLE tableName"); parent::delete(); }
function delete(){ $db = Loader::db(); $db->query("DELETE FROM tableName"); parent::delete(); }
None of these methods seem to work. What am I doing wrong here? All I want is to clean up the database when my block is removed.
I tried this method and it still seems to have no effect on the database, nor am I receiving any errors.
Does the delete() function get called automatically when removing a block or do I have to call it manually somewhere?
Does the delete() function get called automatically when removing a block or do I have to call it manually somewhere?
It gets called manually - but due to versioning it might not happen all the time. It only gets called when no pages or page versions are referencing that instance of the block. Then the block cleans up after itself.
For example, if you add a block to the first version of the page, and then go into a subsequent version and delete the block, the block is gone from that version of the page, but it's still around on the previous version of the page.
A good way to test whether this is working is to add a block to a page, make sure the data is in the table as you would expect, then delete the entire page.
For example, if you add a block to the first version of the page, and then go into a subsequent version and delete the block, the block is gone from that version of the page, but it's still around on the previous version of the page.
A good way to test whether this is working is to add a block to a page, make sure the data is in the table as you would expect, then delete the entire page.
Ok, I see what the problem is now. I was actually confused as to when the delete event fired.
After some more digging I see that I was looking for the uninstall event for the package.
Thanks though, that does clear up a lot of confusion as I thought delete fired when you removed the Block/Package in the backend.
After some more digging I see that I was looking for the uninstall event for the package.
Thanks though, that does clear up a lot of confusion as I thought delete fired when you removed the Block/Package in the backend.
The easiest way would be to use phpmyadmin to get to it and remove it from there.
another option is to install this add-on:http://www.concrete5.org/marketplace/addons/database-manager/...
You can then access your database and tables through the dashboard and remove it from there
another option is to install this add-on:http://www.concrete5.org/marketplace/addons/database-manager/...
You can then access your database and tables through the dashboard and remove it from there