• Resolved kklo

    (@kklo)


    Hi,

    Is it possible to have two WordPress databases in a single template and domain?
    Example: An ecommerce veterinary products and a veterinary clinic.

    The question is that they are different users and some different pages.

    Or would it be better and easier to use a user role manager and page access control?

    Thanks

    kklo

    • This topic was modified 3 years, 8 months ago by Jan Dembowski.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s possible. You’d create a new wpdb class object using the other DB’s credentials. You can then query directly with native PHP mysqli functions, or swap wpdb connection objects into the global $wpdb, which is the default DB connection. Whatever DB that global is connected to is what WP thinks of as its own. Once you’ve made a query to the alternative DB, swap the original object back into the global to restore normal operation.

    Thread Starter kklo

    (@kklo)

    Hi, @bcworkz

    Great thanks a lot.
    I hope to get this setup right.

    Moderator bcworkz

    (@bcworkz)

    I misspoke slightly, apologies.

    You can then query directly with native PHP mysqli functions

    While this is always true, what I should have said is you can then query the alternate DB using the new wpdb object’s methods.
    https://developer.wordpress.org/reference/classes/wpdb/

    Thread Starter kklo

    (@kklo)

    ok,
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Two WordPress databases’ is closed to new replies.