$wpdb->update multiple rows, like IN in normal SQL

As you can see in source code the = sign is hardcoded in the wpdb::update() method, so, by default, is not possible to use IN for update method. Simplest way to do the trick is to use the wpdb::query() with your sql query, just be sure to properly escape all values Example: function wpdb_update_in( $table, … Read more

WPDB prepare – like % – placeholders?

Yes, they’re normal. They were added in 4.8.3 to fix an SQL injection vulnerability. You can read an article describing the technical reasons for this happening here and the ticket for the change here. The placeholder characters are replaced by the random characters on the last line of $wpdb->prepare() with the $wpdb->add_placeholder_escape() function, which calls … Read more

$wpdb->insert not working in any way

When $wpdb method doesn’t perform as it should it is likely issue with resulting SQL query (because of wrong input or something else). Follow wpdb reference in Codex for troubleshooting: enable database error display via $wpdb->show_errors() check what query is being formed and run via $wpdb->last_query

How to use $wpdb to delete in a custom table

The best WP API solution for this goal is to use the delete() function to remove a row. A small example, to delete the raw ‘ID’ in the custom table ‘eLearning_progress.’ $id = 0815; $table=”eLearning_progress”; $wpdb->delete( $table, array( ‘id’ => $id ) ); But I can’t see which raw you will delete in your table … Read more

How do I check for a duplicate record before inserting using wpdb

Let’s say the primary key of the table is my_part_ID. So we will check if there is any primary key value for the combination of user_ID and PL_part_ID as below $my_part_ID = $wpdb->get_var( $wpdb->prepare( “SELECT my_part_ID FROM ” . $wpdb->prefix . “pl_my_parts WHERE user_ID = %d AND PL_part_ID = %d LIMIT 1”, $user_ID, $PL_part_ID ) … Read more

Fetch array with $wpdb

wpdb‘s get_results method takes an optional second argument that lets you specify how the data is returned. The default return is an object. But you can also set it to… OBJECT – result will be output as a numerically indexed array of row objects. OBJECT_K – result will be output as an associative array of … Read more

How to parse row results from $wpdb -> get_results

foreach( $wpdb->get_results(“SELECT * FROM your_table_name WHERE id LIKE’ . $id . ‘;”) as $key => $row) { // each column in your row will be accessible like this $my_column = $row->column_name;} More info here

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)