3

how to update all rows of an table with $wpdb? I tried this, but won't work:

$wpdb->update( 'wp_comments, array( 'comment_karma'  => '123' ), null );

and this

$wpdb->update( 'wp_comments, array( 'comment_karma'  => '123' ), array() );

So how to do this? Thanks in advance!

1 Answer 1

7

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'
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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