Hello,

I have two databases on my website lebphoto.com with the same tables. One with a 1665 members and the other with 33 members, I want to merge them together. is there a way other than typing each records by myself or ask the members to register again?

Thank you

Member Avatar for iamthwee

you can use sql language to do that.

Just make sure you insert them into the correct tables.

Create 2 db connection scripts
connect.php and dbconnect.php
Create 1 script called
create-new.php
Below is the connect.php

<?php
// this is connect.php
// connect to the 33 member database

        $host = "localhost";               // Database server
        $user = "Database username";          // Database username
        $pass = "Database password";                // Database password
        $db = "Database name";       // Database name
    $db1=mysql_connect("$host","$user","$pass");
    mysql_select_db("$db");
    $ok = mysql_select_db("$db");
    if (!ok)
{
    die("<br>" . mysql_errno().":".mysql_errno()."<br>");
}
?>

Below is the dbconnect.php

<?php
// this is dbconnect.php
// connect to the 1665 member database
        $host = "localhost";               // Database server
        $user = "Database username";          // Database username
        $pass = "Database password";                // Database password
        $db = "Database name";       // Database name
    $db1=mysql_connect("$host","$user","$pass");
    mysql_select_db("$db");
    $ok = mysql_select_db("$db");
    if (!ok)
{
    die("<br>" . mysql_errno().":".mysql_errno()."<br>");
}
?>

Below is the create-new.php

<?php
// 33 members database
include("connect.php); 
// for this demo we'll use customer as the table name
// replace the field names with the correct fields from your database table

$sql = "SELECT * FROM customer"; 
    $sql1=mysql_query($sql) or die("Couldn't select customer!");
while($row = mysql_fetch_array($sql1))
     {
    $ID = stripslashes($row['ID']);         // replace the field names only
    $MembersID = stripslashes($row['MembersID']);    // replace the field names only
    $fname = stripslashes($row['fname']);        // replace the field names only
    $lname = stripslashes($row['lname']);        // replace the field names only
    $email = stripslashes($row['email']);        // replace the field names only
// 1665 members database
include("dbconnect.php);  
$insertmember="insert into customer (ID, MembersID, fname, lname, email) values ('$ID', '$MembersID', '$fname', '$lname', '$email')";  
//registering member in database
$insertmember2=mysql_query($insertmember) or die("<br><br>Could not insert customer");
// do not uncomment code below.
//$ID = mysql_insert_id();
echo "Insert $fname $lname Completed Successfully";
    }// Closes While statement
?>

Basically you are connecting to the database with the 33 members and as long as the table and field structure is identical you can then just open a connection to the database containing the 1665 members and append the 33 members to that db.

When completed you will have 1 db with 1698 members.

Have fun.
Arty.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.