I have two sites, one is a subdomain of the other. They both do different things entirely with one unifying goal.

My intent is to have the main site do a majority of the heavy lifting, and the subdomain site to authenticate a very specific function. The issue I run into is with users on the main site being able to access the authentication (subdomain) site without creating a new login.

That is, what method should I use to send/receive username data across two MySQL databases?

I am considering decoupling to achieve this goal, though I presume this may not be the most efficient method or appropriate toward my goal. I am at a loss in describing why this level of functionality is necessary.

EDIT: Here is one approach I am thinking about

As soon as I posted this question I considered the option of have a script run every 24hrs that updates the target database with user accounts from the subdomain database. This would entirely resolve my issue if anyone has resources on scripting MySQL jobs between tables

The overall idea is to create a routine:

Run MySQL Task (every 24hrs)

  1. Open database connection

$connection = mysql_connect("localhost",username,password);

  1. Select source directory (the subdomain)

mysql_select_db("subdomain", $connection);

  1. Run query and fetch array

    $result = mysql_query ("SELECT * FROM wp_users", $connection);
    while ($row = mysql_query_array($result, MYSQL_NUM))
    // Print element in $row
       foreach ($row as $attribute)
          print "{$attribute} ";
      print "\n"
  2. Close statement


  1. Open target database connection

$connection = mysql_connect("localhost",username,password);

  1. Select target database

mysql_select_db("main-domain", $connection);

  1. Prepare

    CREATE TABLE items (
            ID = bigint(20) NOT NULL,
            user_login = varchar(60) NOT NULL,
            user_pass = varchar(255) NOT NULL,
            user_nicename = varchar(50) NOT NULL,
            user_email = varchar(100) NOT NULL,
            user_url = varchar(100) NOT NULL,
            user_registered = datetime NOT NULL,
            user_activation_key = varchar(255) NOT NULL,
            user_status = int(11) NOT NULL,
            display_name = varchar(250) NOT NULL,
    ) type=MyISAM;
    // Make a query
            $query = "INSERT INTO items VALUES (?,?,?,?,?,?,?,?,?,?)";
    //Prepare the query
            $stmt = mysqli_prepare($connection, $query);
    //First row to insert
            $ID = $result[0];
            $user_login = $result[1];
            $user_pass = $result[1];
            $user_nicename = $result[1];
            $user_email = $result[1];
            $user_url = $result[1];
            $user_registered = $result[1];
            $user_activation_key = $result[1];
            $user_status = $result[1];
            $display_name = $result[1];
  2. Execute

  3. Check for errors and halt

if(mysqli_stmt_affected_rows($stmt) !=1)

    die("Something went wrong");
  1. Close statement / close connection


I'm a little stuck on the actual execution portion, but I plan to come back after I have given it more thought and read comments. Thank you everyone.

  • I'm really struggling to understand your issue here and why you think "decoupling" (linked to the bridge pattern) is relevant. If you have two separate databases, why can users on the subdomain access it at all? Commented Jul 13, 2020 at 17:48
  • You can edit your question to include your possible solution and ask if that’s a good solution for the problem.
    – Rik D
    Commented Jul 13, 2020 at 17:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.