• [ Moved to the Fixing WordPress sub-forum. ]

    Hi i have a question i am trying to connect few wordpress database together so i can use functions like get_results, get_user etc but my problem is my i can’t use wordpress multisite because it’s on different severs, i did some research and i found the only and simple way is via $wpdb classes in wp-includes/wp-db.php like this
    ===============================================================================
    $mydb = new wpdb('username','password','database','localhost');
    $rows = $mydb->get_results("select Name from my_table");
    echo "

      ";
      foreach ($rows as $obj) :
      echo "

    • ".$obj->Name."
    • ";
      endforeach;
      echo "

    ";
    ———————-OR———————————-

    /**
    * Instantiate the wpdb class to connect to your second database, $database_name
    */
    $second_db = new wpdb(DB_USER, DB_PASSWORD, $database_name, DB_HOST);
    /**
    * Use the new database object just like you would use $wpdb
    */
    $results = $second_db->get_results($your_query);

    ———————————————————-
    but i don’t know how i am little new at editing WP files ,can anyone help me please
    here the answer i found so far.
    https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database

    https://wordpress.stackexchange.com/questions/181468/how-to-connect-remote-database-in-wordpress

  • The topic ‘Connect wordpress to WordPress to different severs DB’ is closed to new replies.