0

When I run an UPDATE query using $wpdb, WP prepends the database name associated with the WP installation to whatever is passed in the table name argument.

This isn't desirable as my app passes the full path to the table (ie. databasename.table). In the end, what happens is the table name ends up looking like databasename.databasename.table, causing my query to fail.

Is there a way to stop this? I realize I can open a new $wpdb connection to run queries on a different database but I want to use the same connection. SELECT work fine this way, it's annoying that the behavior for UPDATE is different.

$wpdb->update( 
    "database.table", 
    array( 
        'm_title' => $post->post_title,
    ), 
    array( 'id' => $game->id ), 
    array( 
        '%s', 
    )
);
3
  • 1
    Could you elaborate on how are you running query and provide example of the code? Also I would definitely recommend to use separate instance for querying different database. Commented Nov 4, 2013 at 9:05
  • pastebin.com/EkbKRst7 Commented Nov 4, 2013 at 16:22
  • Don't use pastebins etc; please edit your question and paste the code in there. Commented Nov 4, 2013 at 17:12

1 Answer 1

2

The behavior I described in my post only happens when you are using $wpdb->update to execute an UPDATE statement.

If you want to update a different database using the same connection, use $wpdb->query to send a raw query, WP won't modify it then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.