DB Queries not working
-
I’m building a plugin that adds and removes data from a very simple table. I built the queries, called the methods on $wpdb, but the database does not change.
When I output the last query after I run the queries and copy-paste it into phpMyAdmin, they work fine.Here are the key functions:
private function remove_from_db( $s_table, $i_item_id ) { global $wpdb; // get table name $s_table_name = ($s_table == 'cart') ? $this->s_cart_table_name : $this->s_wishlist_table_name; // get user id $i_uid = get_current_user_id(); $s_query = "DELETE FROM {$s_table_name} WHERE uID={$i_uid} AND wID={$i_item_id};"; $wpdb->query( $wpdb->prepare( $s_query ) ); //echo $wpdb->last_query; }
private function add_to_db( $s_table, $i_item_id ) { global $wpdb; // get table name to insert into $s_table_name = ($s_table == 'cart') ? $this->s_cart_table_name : $this->s_wishlist_table_name; // create an array of values to be inserted $a_values = array( 'wID' => $i_item_id, 'uID' => get_current_user_id(), ); // insert values $wpdb->insert( $s_table_name, $a_values ); //echo $wpdb->last_query; //echo 'dadada'; }
- The topic ‘DB Queries not working’ is closed to new replies.