Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:01:31+00:00 2026-06-03T10:01:31+00:00

I wrongly designed my application to have one database to each user. each user

  • 0

I wrongly designed my application to have one database to each user. each user had 3 similar tables. I now want to have one database and 3 tables only; where i will use the database name in the old databases as a reference in the new system. There was another database called “users” in the old database that stored the database names. I’m done with the schema design of the new database and now left with the migration.

enter image description here

The trick here is that I have 3 db connections. I first connect to the users database and userinfo table, pick up the database_name in a loop, use it to connect each old db and further connect to personal, accounts and games table.

After picking up the tables, i will like to populate/join it with the new Database (DATA_ONE) and the tables whiles i append the old database_name to the new tables. Any help on this or is there a better way to do this? Thanks much

<?php

$dbhost = "localhost";  
$dbname = "users"; 
$dbuser = "root"; 
$dbpass = "*****"; 

    $conn1 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " .  mysql_error()); 
    $conn2 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " . mysql_error()); 
    $conn3 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " . mysql_error());

    mysql_select_db($dbname,$conn1) or die("MySQL Error: " . mysql_error()); 

$query  = "SELECT database_name FROM userinfo";
$result1 = mysql_query($query,$conn1);
 while($row = mysql_fetch_array($result1, MYSQL_ASSOC))
    {
 $database_name =$row['database_name'];
 $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
 $db = mysql_select_db($database_name ,$conn2) ;
 // now, pick personal, accounts, games tables of user and populate new database and  tables.
// this is where i need help.   
  }

 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:01:42+00:00Added an answer on June 3, 2026 at 10:01 am

    Why do you think you need 3 seperate database connections with the same credentials? In any mysql query you can reference tables from any database on the same instance by prefixing the table name with the database name (and a . in between). I’d suggest not using ‘database_name’ as an attribute name:

    $databases=get_mysql('SELECT DISTINCT database FROM users.userinfo ORDER BY database');
    $count_of_users=count($databases);
    foreach ($databases as $user_offset=>$user) {
       $uqry="INSERT INTO data_one.personal
         (user, id, address, password)
         SELECT '$user'
         , (id*$count_of_users*$user_offset)
         , address
         , password
         FROM ${user}.personal"; 
        ...
    

    (assuming that ‘id’ is an autoincrement value which may be referenced elsewhere).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem, I have a variable wrongly encoded that I want to fix.
We have an application where user sets his/her preferred date/time format. User is expected
I am new to ASP.NET / .net, i have designed the screens and database
I want to delete some certain characters that used wrongly in a string. ........I.wanna.delete.only.the.dots.outside.of.this.text...............
I have an application server which connects to a database server. I would like
I have a client/server system where one of the wrongly named service calls on
I was wondering how could I remove one (wrongly inserted) entry/word from the ispell
By mistake i installed PEAR , I think i installed very wrongly, Now i
Ive entered the base URL wrongly in the backend and now everything loads bad.
Every now and then my keyboard in Visual Studio starts to behave wrongly. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.