Yes it works!
This is the code, assuming both the databases share the same username & password:
$wpdb->select('mydbname');
wp_cache_flush();
Once done, re-issue the same statements, with the original database name.
Can’t see any performance issue at the moment, maybe because this is done when building a custom form picking data from two posts out of two databases.
It may impact performance when used on a large amount of rows in batch loop…
Related Posts:
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Difference between partition key, composite key and clustering key in Cassandra?
- How SID is different from Service name in Oracle tnsnames.ora
- What is a relation in database terminology?
- Why WordPress choose data serialization over json_encode?
- Relaunch 4.2 utf8mb4 database upgrade
- Get error messages when $wpdb->insert() returns false?
- Does dbDelta delete columns as well?
- Reset Post IDs to less than 64bit integer
- Where can I find the database changes between WordPress versions?
- Does WordPress use the InnoDB engine for MySQL by default?
- $wpdb->prepare() warning in WordPress 3.5
- When is it appropriate to create a new table in the WordPress database?
- Special characters in WordPress UTF-8 [closed]
- Best way to import users, post and categories from an external database
- Performance tips for a large user base [closed]
- How to delete outdated, wrongly sized images in _wp_attachment_metadata?
- wp_options is GB in size
- Can’t update database after wordpress update from 3.8.1 to 4.4.1
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Extend the wp_users table
- Why does WordPress rely on an fully qualified site_url with a 15-step plan for moving a site?
- I have a problem with my WordPress DB after I tried to install multi-site
- Database sync between local and production
- Database error Deadlock found when trying to get lock; try restarting
- Connect Second Database to WordPress
- update_user_meta() does not work
- Query from a different database than the default
- Need of separate security plugins for both root and subfolder sites WordPress?
- Error: SELECT SQL_CALC_FOUND_ROWS
- How can I create a Bible search engine via WordPress? [closed]
- Error establishing a database connection; After importing DB & Theme
- Check if column exists for one table in DB
- wp_get_current_user always returns 0 continued
- Insert post in another database
- Improve performance by removing unnecessary database queries
- Redirecting to old domain after migration website
- Localhost keeps redirecting to live domain
- How to get membershiplevel from WordPress Database?
- Unable to set a default serialized array using dbdelta()
- Child parent relationship inside WP DB
- Copying database tables to new database
- Duplicating Complete WordPress Install for Development and then Redeployment?
- What does wp_term_taxonomy.parent reference?
- How to combine multiple wp_insert_post into one in order to gain better performance
- How to get nav_menu_item_id and slug from wp database
- Two prefixes in database? Which one is valid?
- Is there a way to execute a php script outside WordPress?
- How can I restrict php mail() to only send me one email after a db error
- pull data from a remote wordpress database
- Change the default data installed when setting up WordPress
- How to delete post comments from the database via SQL statement?
- Users table missing from Database [closed]
- Why does changing Database Table Prefixes result in loss of content?
- How to connect and insert data in database of wordpress?
- $wpdb->get_var – What value is returned when zero records are found?
- wp_option table error while importing
- wp_insert_user not creating account correctly when ID is manually set
- SymmetricDS in dev + prod workflow?
- Fixing YARPP plugin FULLTEXT MySQL indexing
- What is wrong here? Issue with post_id and meta_value
- Error establishing a database connection in wordpress site , website not opening
- Counting post and changing roles in mysql database. Query not code
- wpdb Insert unknown post data dynamic foreach loop
- How do I use a database in a custom theme?
- Deleting empty meta key values
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- WP 5.5, child themes, customizer and a weird cache issue
- How do you enable scripts on a WordPress installation in Softaculous?
- How do I change several broken URLs in a several wordpress databases in the fastest way?
- How to rerieve comments and their replies from DB
- Inserting data with Geometry field
- Best way to store 1 billion+ posts?
- Export only a part of the database for migration
- Why am I being prompted to reinstall wordpress?
- What’s the easiest way to connect external database and display data on wordpress?
- database error WordPress move from one hosting to other
- Character encoding issue – black diamond question marks on imported post excerpts
- Same DB for live and dev versions
- update multiple user meta field based on another meta field
- After renaming MySQL database, I can no longer access my Blog page
- Reinstall wordpress/mySQL caused database problem
- How To connect to the same WordPress database with different database user
- execute custom function on database connection error
- Call to a member function insert()
- I have include wp-config, should I add global $wpdb also?
- Create a new table on the database and save parameters from a contact form
- not saving post in wp_post wordpress database table
- How to have WP Search widget index dynamically generated content?
- Preventing concurrent update of data
- How to add data from wordpress tables to new database tables you have created
- Category not displaying in add post, edit post, and categories page.
- Creating Tables in WordPress Database
- Calling update_user_meta inside of another function doesn’t work
- How to back-up a database on IIS
- $wpdb->prepare returns empty array
- Prevent creation of unused database tables?
- How to store a plain password in WordPress database in another field
- Where are database files of a WordPress website?
- WP Multisite Users Not Linking