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?