Reading through the source code for the wpdb
class, I see no reason why something like this shouldn’t work:
$otherdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$otherdb->prefix = 'wp2_';
And then (if I’m understanding this right) you can use all the existing $wpdb
methods and variables. Eg:
$x = $otherdb->get_results( $sql_query );
(If I’m wrong — or if this is bad practice for reasons I haven’t considered — please feel free to correct me.)
Related Posts:
- Checking if Database Table exists
- Staging sites, how do you manage synchronising updates in the DB?
- How to get the post publish date outside the loop?
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- Using transients in conjunction with memcached
- How to define composite keys with dbDelta()
- Is it possible to define two databases for one installation?
- Has parent field in the table wp_term_taxonomy has term_id or term_taxonomy_id
- Forcing nickname as display_name in custom edit profile template
- Syncing local content with development / staging sites
- Export WP database for import using WP-CLI on Vagrant Box
- Improve or optimize a very slow query
- What is the advantage of separating wp_users and wp_usermeta table?
- Showing content from another wordpress installation database in the page template loop?
- Multiple WP install with same users database
- Dynamic data in `wp_register_script` needed
- “MySQL server has gone away” since update to 3.8
- WordPress page title repeated in SOME pages
- Why is $wpdb->get_results failing on certain tables but not others (which have data)?
- How to correctly add a table to the WordPress MySQL database
- MySQL Syntax Error upon restoring database from backup [closed]
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- How to verify password outside WordPress?
- Is it safe to convert tables from MyISAM to InnoDB?
- Use one WordPress database with multiple instances of one site
- Who is responsible for data sanitization in WordPress development?
- How do I properly update the WordPress database password?
- wpdb_prepare with multiple or condition
- How to check if a core update, like 4.9.8 → 5.0, involves a database update (migration)?
- $wpdb->insert is not working
- WordPress Install and Database on separate hosting?
- Moving a site from a temporary domain to the live domain [duplicate]
- Error establishing a database connection on Installation
- Moving WP from local server to live, error establishing a db connection
- delete post meta from db, even if does not exist?
- In what part of the WordPress core does the users table and usermeta table get joined?
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- Output custom content not from the posts table?
- Exporting table to csv works in the admin but exports HTML data when used on the front end
- wp search-replace (not executing)
- Reducing Database Query Time
- How can I get my wordpress password from an SQL file?
- Create table from array with prepare
- Migrate database between 2 different wordpress version
- Is there an atomic way to update_option in WordPress (to ensure data integrity)?
- SSO system between 2 WordPress installs on different servers
- Form that sends data to an admin panel and can export it
- All text disappeared (seems to be a database problem) [closed]
- Convert user passwords to MD5?
- is wordpress stores Role Id in WP database?
- Why do database examples sometimes finish with an add_option call?
- Does post_meta data need to be unserialzed?
- How to backup my site and restore my wordpress site
- How to fetch records from database WordPress
- How and where is wordpress adding mySQL content to database?
- How get Data form wordpress database as array not stdclass?
- cannot connect database
- How to delete a particular row in a database table
- Multiple WordPress sites installs sharing the same database but with different content and domains
- Brandoo WordPress Unable to Update to WordPress 4.2.2
- Connecting to wordpress database in my application [closed]
- Remote database -> massive response time increase?
- Custom Post Type not showing anything added by code anymore?
- change the year on all of my custom post types?
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- Delete user with only subscriber role
- WordPress keeps redirecting to localhost
- get value from ‘terms’ table
- custom tables in wordpress Database? (can i just create them with sql?)
- How to rename custom table name programatically in wordpress?
- Displaying requested data from a the database in wordpress
- Accidently changed the GUID
- How to edit custom table data in frontend
- pre_get_posts causings DB error when using ( ‘posts_per_page’, -1)?
- generate PDF from member information
- mysqli_query(): MySQL server has gone away for Curl Request
- Help posting values to DB on submit using $wpdb->query
- Restore Old Database Over Newer WP & Plugin Files
- create a table using user meta custom data
- wpdb query to insert images in to post/page gallery
- Creating a database in my plugin not working
- How to create index (sql) to a meta_key?
- Not sure what to do next to optimize
- Database structure for thousands of posts
- WPCLI search and replace in a particlar site dir effect another site-dir
- get_user_meta and umeta_id
- $wpdb not working
- Accessing content from third party as native posts in WordPress
- One WP Database outside localhost and two connections
- Send data to database after redirect (and popping out of iframe)
- Fetch data from another site, but the same database
- Simple email input store in database
- Pulling values from a sepcific row in table
- Every time I update or install a plugin I get “Error Establishing a Database Connection in WordPress”
- import (migration) user database to wp-users
- Insert Extra fields added in the front end registration form to DB
- $wpdb->insert not working for last select option
- How to create a table [closed]
- Upload wordpress from localhost to 000webhost
- Query a meta key using an array of values where the database value is a string