I am using Wordpress 3.4.2, latest version! I have no plugins installed except the one that I am writing.
So Here's the deal, I'm reading a json feed and i'm trying to import its content into a table that i created in my wordpress database. I've used a similar set of code in another plugin that I wrote and it works fine there. I do not understand why it does not work here.
When i run this different plugin that i am writing i am get the dreaded and oh so clear "WordPress database error: [Query was empty]".
Here is my code...
// Setup the array
$values = array();
foreach ($bugs as $bug) {
$status_text = $bug['text'];
$tContent = htmlSpecialChars(html_entity_decode($status_text));
$imported = 2;
[ shortened to keep this post short, but other values are listed here. ]
// for the values insert part
$values[] = '("'.$tContent. '", "'.$imported.'")';
}
if(is_array($values)) {
echo "<hr><strong>WHAT TO IMPORT?</strong><br/>";
var_dump(implode(',', $values));
}
This output all of the values as expected. Everything is wrapped in parentheses and seperate by a comma.
Then i do this...
global $wpdb;
$table_name = $wpdb->prefix . "bugtbl_temp";
$sql = $wpdb->prepare (
"INSERT INTO $table_name
(`post_content`, `imported`)
VALUES ". implode(',', $values) . " ON DUPLICATE KEY UPDATE imported = 1"
);
$wpdb->query($sql); // execute query
$wpdb->print_error(); // any errors?
$wpdb->last_query; // show the qry
$wpdb->flush(); // cleanup
And then when i run this function I get the "WordPress database error: [Query was empty]" and nothing is imported into my table.
I saw on here one other guy was having problems with $wpdb->prepare. Am I using it incorrectly?