I have a database table that a user can add to and remove data from within my drupal module. What I would like to do is automatically check to see if the table is completely empty after every delete, in which case I would like to run an “ALTER TABLE” to reset the auto increment to 1. However I am having trouble building a function that does this for me.
How can I implement a function to automatically detect if all fields are empty, and automatically reset the increment without the need to go into the database and apply ALTER SQL manually?
Here is some of the code…
function achievementlist_entry_delete($form, &$form_state) { foreach(($form_state['values']['table']) as $rows) { $num_deleted = db_delete('achievements') ->condition('achvmntID', $rows) ->execute(); } //Here I would like to check the "achievements" database, as well as ALTER TABLE //it is empty }