WordPress.org

Ready to get started?Download WordPress

Forums

Accessing non-wp database in plugin (2 posts)

  1. dtech
    Member
    Posted 1 year ago #

    For my plugin I need to pull some info from another local (non-wordpress) MySQL database. Is there a standard way to do this in wordpress (e.g. create a new wpdb object) or should I just use the normal mysql/mysqli/PDO code?

  2. lahiru
    Member
    Posted 7 months ago #

    You probably found the answer by now but for anyone else coming here from search engines (like me), I found the answer here:

    Stackexchange
    Stackoverflow

    It's quite simple. Basically:
    $newdb = new wpdb( 'user', 'password', 'database', 'hostname' );

    Then use all the WordPress functions:
    $newdb->get_results("SELECT your query");

Topic Closed

This topic has been closed to new replies.

About this Topic