Custom INSERT statement and using wpdb->prepare

I’m in need of a little how-to here. I’ve read the codex but I find them to be a bit confusing so I’m really understanding how to write my SQL INSERT statement using $wpdb->prepare. I do want to protect my query because I want to be able to use this code in a plugin.

So, here is what I have. I’ve shortened it to keep this post on track.



foreach ($items as $row) {
$values[] = '("'.$ID.'", "'.$ijAuthorID. '","' .$tPubDate. '","' .$tContent. '","' .$tTitle. '","' .$tPostName. '","' .$tPostType. '","' .$tImported. '","' .$tID. '")';
}

$sql = "INSERT INTO $tablename (ijID, ijAuthorID, ijDate, ijDescription, ijTitle, ijSlug, ijPostType, ijImported, ijUKID)
VALUES ". implode(",",$values) . " ON DUPLICATE KEY UPDATE ijImported = 1";
$wpdb->query($sql);


All of this works great. It imports the data into the table and if it comes across any duplicates it changes the ijImported value to 1.

I have tried to rewrite the query above using the example from the codex, but all I get is an error that says my query is empty. :frowning:

What I dont get is how to rewrite this INSERT statement so that it uses $wpdb->prepare. This is where you come in. Can someone take a stab at explaining to me how $wpdb->prepare should be used in this instance?

Thank you in advance!