<?php 

/********************************************************************************************

GNU General Public License 2.0 (http://www.gnu.org/licenses/gpl.html)
Developed By: Sheikh Arfeen Arif (http://www.meripasand.com/)
Contributed By: All Members of this project (http://code.google.com/p/mysqldatacopy/)

Please contribute back to community as others do.

Project: mysqldatacopy
URL: http://code.google.com/p/mysqldatacopy/
Version: alpha 0.1 (April 04, 2007)

********************************************************************************************/



// varibles for database connection

// New Database Varibles
$host = "localhost"; // db server address
$db = ""; // db name
$user = ""; // db username
$password = ""; // db password

// OLD Database Variables
$old_host = "localhost"; // db server address
$old_db = ""; // db name
$old_user = ""; // db username
$old_password = ""; // db password

/*********************************************************************************************/

// BOTH DATABASES SHOULD BE ON SAME MACHINE FOR RIGHT NOW - YOU EXTEND THE CONNECTION 
// FUNCTION FOR MULTIPLE MACHINES.


// main connection function -- used only for same machine
function Connect()
{
$dbserver = mysql_connect($host, $user, $password) or die("Cannot connect to server ".$host);

mysql_select_db($db, $dbserver) or die("Cannot connect to database ".$db);
mysql_select_db($old_db, $dbserver) or die("Cannot connect to database ".$old_db);

}

// DB disconnet function
function Disconnect()
{
mysql_close();
}

/*********************************************************************************************/

// getting column for the old database
	function GetOldCol($colname, $tablename)
	{
		$res = mysql_query("SELECT ".$colname." FROM ".$this->old_db.".".$tablename);
		print mysql_error();
		$num = 0;
		while ($row = mysql_fetch_array($res))
		{
			$num = $num + 1;
			$data[] = array('num' => $num,
			$colname => $row[$colname]);
		}
		return array($data,$num);
		}

		
		
	// adding into new database
	function AddIntoNewCol($colname, $tablename, $valuetochange)
	{
	mysql_query("INSERT INTO ".$this->db.".".$tablename." (".$colname.") 
	VALUES ('$valuetochange')");
	print mysql_error();
	}
	
	
		// updating into new database
	function UpdateCol($colname, $tablename, $valuetochange)
	{
	mysql_query("UPDATE ".$this->db.".".$tablename." SET (".$colname.") = ('$valuetochange')");
	print mysql_error();
	}
	
/*********************************************************************************************/

?>

<?php 
// connecting to database
Connect();
list($data) = $oGeneral->GetOldCol('old_col_name', 'old_table_name');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Data Copy / Move</title>
</head>

<body>
<h2>Data Copy / Move (alpha 0.1)</h2>
<p></p>
<h4>Table Name</h4>


<?
	if (is_array($data))
    {
    	foreach ($data as $values)
    	{

// adding to the member_id to the new shiplands db
AddIntoNewCol('new_colname', 'new_table', $values['value_get_from_array_old_col_name']);

?>

<?php 
// if you want to print the values on screen.
echo $values['value_get_from_array_old_col_name'];
?>
<br />
<?
        }
    }
?>
</table>
</body>
</html>
