Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using $wpdb to connect to a different database than my WordPress one like this:

$newdb = new wpdb(DB_NEW_USER, DB_NEW_PASSWORD, DB_NEW_NAME, DB_NEW_HOST);

I need to insert multiple rows into the database. I used the code from this StackOverflow answer.

To run the query, I used the following code:

$newdb->query( $newdb->prepare("$query", $values));

When I did echo $query, this's the result: (there are more than 3 columns, but I shortened if for times sake)

INSERT INTO table (column1, column2, column3) VALUES ('%s', '%s', '%s')

When I did var_dump($values), it returned an array with the same amount of strings as I have columns.

When I ran the query, I got the following error:

WordPress database error: [Query was empty]

I tried selecting from the database in a similar fashion and it did work, so my connection to the db is working.

What am I doing wrong?

share|improve this question

closed as off-topic by toscho Oct 3 '13 at 8:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2  
can you provide us more code please? –  iEmanuele Aug 8 '13 at 17:57
1  
Is your table actually named 'table'? And your column names are correct? Is $values an array of three elements? –  s_ha_dum Aug 8 '13 at 18:18
1  
Does it work if you use $newdb->insert( $table, array( 'column1' => 'value1', 'column2' => 'value2', 'column3' => 'value3' ), array( '%s', '%s', '%s' ) ); in place of $newdb->query( ... ); ? –  Pat J Aug 8 '13 at 19:31
1  
thanks for your efforts, but I realized that I had an extra placeholder in the query. When I took it out, it worked. –  user2306941 Aug 8 '13 at 19:34
    
can you split up your $newdb->query( $newdb->prepare("$query", $values)); in 2 steps, and make a var_dump() on each? $p_query = $newdb->prepare("$query", $values); var_dump($p_query); $result = $newdb->query($p_query); var_dump($result) –  Puggan Se Aug 13 '13 at 17:16

Browse other questions tagged or ask your own question.