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.
    – Rarst
    Nov 4, 2013 at 9:05
  • pastebin.com/EkbKRst7
    – relm
    Nov 4, 2013 at 16:22
  • Don't use pastebins etc; please edit your question and paste the code in there.
    – Pat J
    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 that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.