Support » Plugin: Separate Login » Trying to connect to external db

  • Resolved bonesteelkat

    (@bonesteelkat)


    Hello! so what I’m trying to do is exactly what the person at this link was trying to do but I see that were never able to update on their progress. I am trying to edit the code on the page recommended in that thread, but I’m not sure I’m doing the right thing and I thought you might be able to help me. I instantiated a new wpdb object called “mydb” like this:

    $mydb = new wpdb(‘username’,’password’,’database’,’host’);
    (with my credentials of course)

    After that I edited every instance of wpdb related to login and password to be mydb so the queries look like this:

    $seplog_check_login_user = $mydb->get_row( $mydb->prepare(“SELECT * FROM customer WHERE username = %s OR email = %s”, $seplog_user_login_posted, $seplog_user_login_posted));

    I also changed ‘user_id’ to customer_id, as that’s what’s in my table. Obviously it did not work, but that’s why I’m here. I’m not a great coder, so here we are.

Viewing 6 replies - 1 through 6 (of 6 total)
  • An additional question I thought of:

    For lines like this–

    "INSERT INTO seplog_sessions SET token = %s, customer_id = %s, session_start = %d, session_end = %d, last_interaction = %d, level = %d, ip = %s"

    –which insert something into a table I don’t have, do I need to create these in my database so that it will match?

    Plugin Author Christian Gatti

    (@christian-gatti)

    You’re definitely in the right direction!

    • DB tables “seplog_sessions”, “seplog_translate” and “seplog_users” have to be placed into your external DB (you can use phpMyAdmin export/import functions)
    • add into separate-login.php your new wpdb instance: $mydb = new wpdb(‘username’,’password’,’database’,’host’);
    • search and replace $wpdb with $mydb into all plugin files

    You’ve done!

    “seplog_sessions” table is used to manage login sessions, so you must create it in your db too.

    Regards,
    Christian

    Thanks for the quick reply! I will do as you suggest and let you know if I need any more help/if it all works out.

    So I edited as you instructed and I think it worked(?), but I’m getting these errors (from another plugin that is for debugging):

    Warning mysqli_real_connect(): (HY000/2002): Connection timed out on line 1540 in file /home/mysite/dev.mysite.com/wp-includes/wp-db.php
    Warning mysql_connect(): Connection timed out on line 1570 in file /home/mysite/dev.mysite.com/wp-includes/wp-db.php
    Notice mysqli_query(): send of 60 bytes failed with errno=32 Broken pipe on line 1877 in file /home/mysite/dev.mysite.com/wp-includes/wp-db.php
    Warning Error while sending QUERY packet. PID=32548 on line 1877 in file /home/mysite/dev.mysite.com/wp-includes/wp-db.php

    I’m wondering if this is a database error or something that I did wrong. I’m using google cloud platform’s free trial just to test the database.

    Plugin Author Christian Gatti

    (@christian-gatti)

    I’m afraid I can not help you with those problem since I guess they are not strictly caused by Separate Login Plugin.

    Okay, thank you for your help. I will keep working on it!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Trying to connect to external db’ is closed to new replies.