wpdb prepare syntax

Just look at the generated string:

INSERT INTO 'wp_table' (id, datea, one, two) VALUES (1, '2013-12-24', 3, 'NULL') ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two);

The problem is the quotes around the table name. (Your hand-written query has no quotes around the table name, and works.) prepare is intended for dynamic user supplied, content, and it is intended for use with strings and numbers. The table name is neither– not in the same way that your content is. It is going to supply quotes, which is going to break your query.

You should be able to simply write the table name into the query.

$arr = array();
array_push( $arr, 1, '2013-12-24', 3, 'NULL');
$sql_prepare = "INSERT INTO {$wpdb->prefix}table (id, datea, one, two) VALUES (%d, %s, %d, %s) ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two);";

Leave a Comment