Skip to:
Content
Pages
Categories
Search
Top
Bottom

Multiple Databases one one site

  • @shadynicnack

    Participant

    I’m a bit new and trying to get back into wordpress again. I have a wordpress website that needs to use the wordpress database that we first set up, and 2 external databases to obtain information and even at times to edit, and update information. Tried using external database but that is for one external database coming in. Want to use an external database to first set up login meaning when they enter username and password, it will find it through g h the external database. So my question is… What is the best way this situation? If it is coding, is there some tutorials that I can do this?

    Did some research, and someone said that I can use this code in the functions.php to help access another database… Is it functions pho in main or themes?

    $newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
    $newdb->show_errors();

    So I add this in the functions, but where do I put the second database’s info like host, username, password and etc? Where do I put the query code at?

    Will this work to connect to an external databases?

    Please Help!!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • @robin-w

    Moderator

    not really a bbpress question, but this should help – in effect you do each query/set with the connection details.

    $user="xxx";
    $password="yyy";
    $database="zzz";
    $host="aaa";
    $con=mysqli_connect($host,$user,$password,$database);
    $query="select user_email from wp_users where ID=".$id ; 
    $result = mysqli_query($con,$query) or die("failed to get result1"); 
    

    or

    to update

    $update= "UPDATE wp_posts SET post_content =\"".$post2."\" WHERE ID=".$id2 ;
    mysqli_query($con,$update)  ;	
    	

    @shadynicnack

    Participant

    So where do you place the code? Do we make a new file and include it in the wp_config? Do we do each query/set per page or in a function? Is it possible to use an external database connecting to your login?

    @robin-w

    Moderator

    ok, given your answer, sorry but I don’t think you are going to achieve this.

    To do what you want would require a level of wordpress and PHP knowledge that you don’t have – don’t take this as a criticism, I know virtually nothing of say Joomla, or deep sea trawling, or brain surgery. That doesn’t make me stupid, I just don’t have the knowledge on these things to be able to do these things. Nor could someone talk me through this in a forum.

    I’d suggest you hire someone to achieve what you want.

    @robkk

    Moderator

    @shadynicnack

    You are probably going to end up using this plugin, I do not really have much knowledge of setting it up for what you want though.

    https://wordpress.org/plugins/hyperdb/
    https://codex.wordpress.org/HyperDB

    @robin-w

    Moderator

    support for that plugin looks non-existent, and there are doubts on it working with 4.4.x

    @shadynicnack

    Participant

    Here is what I figured so far….

    – I had created a new file wp-custom-config.php
    – Use define define( ‘NEW_HOST’, host name); and other details.
    – And add code for DB connect like below

    $newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
    $newdb->show_errors();

    – Included this file in wp-config.php file.

    So the wp-customer-config.php looks like:

    $DB_NAME_EXT = ‘database’;

    /** database username */
    /*define(‘DB_USER_EXT’, ‘username’);*/
    $DB_USER_EXT = ‘username’;

    /** database password */
    /*define(‘DB_PASSWORD_EXT’, ‘password’);*/
    $DB_PASSWORD_EXT = ‘password’;

    /** database hostname */
    /*define(‘DB_HOST_EXT’, ‘host’);*/
    $DB_HOST_EXT = ‘host’;

    global $newdb;
    $newdb = new wpdb($DB_NAME_EXT, $DB_USER_EXT, $DB_PASSWORD_EXT, $DB_HOST_EXT );
    $newdb->show_errors();

    Like I mention before, I have included it or should I say required it in the wp-config.php at the bottom after require_once(ABSPATH . ‘wp-settings.php’) and looks like…

    require_once(ABSPATH . ‘external-config.php’);
    _______________________________________________________

    FIRST QUESTION: – I read that you can use $newdb in any file any where. How would you do that? Can I see examples?

    SECOND QUESTION: I want to use the $newdb for the login page. So instead of using the $wpdb, I want to use $newdb to pick and check username and password. How would I do that? Would I need to make a custom login page or can I go into the code and switched databases around? Whats the best practice?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar