$wpdb->prepare not working with update table prefix

Your problem is likely that $wpdb->jch_gigs is undefined. Is jch_ the prefix of your DB tables, as defined in wp-config.php? If so, try this: $wpdb->prepare( “UPDATE {$wpdb->prefix}gigs SET available = available – %d WHERE ID = %d”, $quantity, $item ) ); wpdb class on the Codex

WPDB: how to get the value of a field in a custom database table

OK, so first of all, you should always use proper escaping, when building the queries. This is how your code can look after fixing: global $wpdb; $value = $wpdb->get_var( $wpdb->prepare( ” SELECT column_name FROM {$wpdb->prefix}plugin_table WHERE ID = %d “, get_current_user_id() ) ); The things you have to take care of: You have to change … Read more

How-To: wpdb Insert Record With Date

date does not take a human readable string. It takes a Unix timestamp. You need to convert that human date to a timestamp with strtotime. ‘begin_date’ => date(‘Y-m-d’, strtotime(‘2012-08-14’)), Of course, there is really no need to convert a YEAR-MONTH-DAY date into a timestamp only to convert it back that a YEAR-MONTH-DAY format.

$wpdb prepare issue with mysql DATE_FORMAT

From the Codex page for the WPDB class: […] the prepare method […] supports both a sprintf()-like and vsprintf()-like syntax. Having a look at PHP’s documentation for sprintf(): ##Example 6 … // notice the double %%, this prints a literal ‘%’ character So you can use $result = $wpdb->get_var( $wpdb->prepare( “SELECT DATE_FORMAT(report_date, ‘%%d-%%m-%%Y’) FROM table … Read more

Set media metadata (i.e. “dimensions” field) on SVG file after extracting it with a filter

The wp_update_attachment_metadata filter fires every time you upload an image through media library (specifically every time wp_update_attachment_metadata function is being called). So when an svg file is uploaded we check if the file has the desired metadata, the width and height. If not, we generate the metadata as you did in your wp_get_attachment_image_src filter. Now … Read more

How do you use prepare when asking for a list of id’s

$wpdb->prepare() use the same syntax for formatting like php’s printf(). SSo you will need something like … WHERE post_id IN (%d,%d,%d) … This will fit for three ids. But what if we got more or less than three ids? We will use the php tools to create the needed formatting string (assuming $ids is an … Read more

Updating all rows of table with $wpdb

It will not work as the update statement requires a selector to narrow down what to update. You should use a general query. For your needs use this: $wpdb->query( $wpdb->prepare( “UPDATE $wpdb->comments SET `comment_karma` = %s”, ‘123’ ) );

WordPress insert NOW() in TIMESTAMP column returns all zeros

I hadn’t tried to reproduce it, but the likely reason is that what you want to use in query is SQL function (NOW()) but what you “tell” WordPress to use is a string. Declaring its format to be %s means it is sanitized and put in quotes, making it something like ‘NOW()’ which MySQL probably … Read more

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