I am attempting to delete a row from my DB.I am using inputs from the user and I need to be able to sanitize using the prepared statement.

The query itself looks like -

DELETE FROM wp_thing_assignment WHERE (account_number,user) values (1, 'DudeDev')

I am using the following code -

    $success = $this->wpdb->query($this->wpdb->prepare(
        "DELETE FROM $this->table_name WHERE
            values (%d, %s)",
            array ( $this->company[$i], $this->employee)

I get this error -

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values (1, 'USER')' at line 1

Is there any way to salvage this query?

2 Answers 2


I think you have just confused syntax with INSERT :) According to manual the DELETE syntax is:

    [PARTITION (partition_name,...)]
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]


Rather than forming this query manually you should consider using $wpdb->delete() helper.

  • You are correct. I have replaced my query with one using the DELETE helper and it worked fine. Thanks a ton. Commented Oct 13, 2014 at 19:25
  • @Aaron please note it's considered more in line with site's mechanics to post solution as an answer rather than edit it into question.
    – Rarst
    Commented Oct 13, 2014 at 19:40

UPDATE - (SOLVED) My query now looks like -

    // Using where formatting.
    $success = $this->wpdb->delete( $this->table_name,
                    array( 'account_number' => $this->company[$i], 'user' => $this->employee ),
                    array( '%d','%s' ) );

This works perfectly.

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.