Plugin Dev SQL Help Please
-
Hi Guys,
I am creating a couple of plugins, they work ok and I am using the WordPress update_option(key,value) and get_settings(key,value) while testing.I want to emulate these functions with my own table and add a couple of fields plugin_name and theme_name, this is to enable clean up of the tables when a one of my plugins is deleted or a theme is deleted.
I copied the table structure for table wp_12_options and added my fields, the table is created and I can see the empty table and all the fields.
I created the function below to insert and update the records but is is not working, I am not an expert with mysql but I cannot see anything wrong with the SQL strings so a second set of eyes would help
function drf_update_option($optionname, $optionvalue){ global $wpdb; $drfoptionname = $optionname; $drfoptiovalue - $optionvalue; $drftablename = $wpdb->prefix . "drf_plugins"; $pluginname = 'style_switcher'; $themename = stripslashes(get_current_theme()); $drfdb = $wpdb->get_results("SELECT * FROM '$drftablename' WHERE option_name = '$drfoptionname' ORDER BY id DESC", OBJECT); if ($drfdb) { $theid = $drfdb->id; $updatedb = "UPDATE $drftablename SET option_value = '$drfoptionvalue', WHERE id='$theid'"; $results = $wpdb->query($updatedb); } else { $updatedb = "INSERT INTO $drftablename (blog_id, plugin_name, theme_name, option_name, option_value) VALUES (0,'$pluginname', $themename, '$drfoptionname', '$drfoptionvalue')"; $results = $wpdb->query($updatedb); } }Test insert
drf_update_option('supper', 'fish and chips');Thanks in advance
David
The topic ‘Plugin Dev SQL Help Please’ is closed to new replies.