SOLVED!
Solution posted below..
Hello guys..!
I'm having some trouble transferring some data dynamicly from one table of the database to another.
The Database and Table Structure is IDENTICAL. But the data, and entry KEYS are DIFFERENT.
What I need to do is to transfer data from `DB_1.DATA_TABLE` to `DB_2.DATA_TABLE`, but the Entry KEY must be specific and I want to create that Key by my own.
I need to do this loop for about 20 different tables, and every table have different structure.. Only the Source\Target DBs ar Identic.
I am doing this in a loop, I am trying like this now, but cant get it working:
Note: All the Variables are passed correctly, I just need a correct syntax to get this working.
PHP Code:
while($TransferData = mysql_fetch_array($SqlSource)) {
KOV::reconnect();
mysql_query("INSERT INTO `wow_characters_target`.`account_data` (`accountId`) VALUES ('" .$SqlTarget['accountId']. "') SELECT * FROM `wow_characters_source`.`account_data` WHERE `accountId` = '" .$TransferData['accountId']. "'");
}
I made a solution my self, and the problem is solved. Thank you!
PHP Code:
# This code here is located in another loop..
$SqlGetStructure = mysql_query("DESCRIBE `" .$table_name. "`");
$ConstructedData = array();
$ConstructedColumns = '';
$ConstructedValues = '';
# Make an Array with the data needed to insert into the Target Table..
while($DescribeData = mysql_fetch_array($SqlGetStructure)) {
if($DescribeData['Field'] != 'accountId'){
$ConstructedData[$DescribeData['Field']] = $TransferData[$DescribeData['Field']];
}
}
# Set the Unique data..
$ConstructedData['guid'] = $SqlLastId['guid']+1;
$ConstructedData['account'] = $target_key;
# Construct the Structure and Values to be Mysql Query Ready..
foreach($ConstructedData as $key => $data) {
$ConstructedColumns .= '`' .$key. '`,';
$ConstructedValues .= "'" .addslashes($data). "',";
}
$ConstructedColumns = substr_replace($ConstructedColumns ,"",-1);
$ConstructedValues = substr_replace($ConstructedValues ,"",-1);
# Execute the Query
$Execute = mysql_query("INSERT INTO `characters`(" .$ConstructedColumns. ") VALUES (" .$ConstructedValues. ")");
Thank you for your help,
Ralph!