Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This sql query

$wpdb->query("UPDATE log SET total=total+1 WHERE id='1')");

How do I turn it into $wpdb->update() statement?

Ex.

$wpdb->update('log', array('total'=>'total+1'), array('id'=>'1'));
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You don't. Not with the WPDB update() function. The update function assumes that the values of the columns are strings. You can override that with the format parameter, but that only allows %d, %f, and %s (integer, float, string). It doesn't allow operations on columns like total+1.

You'd have to use the query() function directly to do your update.

share|improve this answer
    
I do try many method, still not work. $wpdb->query should be the only way, Thanks –  supersuphot Sep 22 '12 at 10:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.