DROP plugin table – dbDelta = no good
-
Hi.
This is my first time posting here, so if this kind of topic is not appropriate, please direct me to a better place. I was reading an article in the codex titled Creating Tables with Plugins. This article explains how to create a database table via the activate_ hook. The first thing that came to my mind was “can you delete the table upon deactivate_”? I successfully accomplished this, but not without problems. The dbDelta function does not handle DROP statements therefore I had to hard code the query.My question is: “Is it better to code database interaction by hand or by using WordPress’s db handling functions?” My plugin’s “Deactivate” section looks like this:
add_action('deactivate_'.$plugin_path,'jal_uninstall');
function jal_uninstall () {
global $table_prefix, $table_suffix, $wpdb;
$table_name = $table_prefix . $table_suffix;
$sql = "DROP TABLE $table_name;";
mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
mysql_select_db( $table_prefix . DB_NAME );
mysql_query( $sql );
}
Is there a function in WordPress core that is better suited to carry out the DROP?
Thanks in advance,
_m
- The topic ‘DROP plugin table – dbDelta = no good’ is closed to new replies.