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

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

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *