Skip,
I just wrote myself a little macro to get all of the right fields in the right place some months ago. I'll see if I can dig it out if I can find it later and apply it to that table.
However, it won't matter whether the field is auto_increment or not on source or destination. The script is intended to pretty much "copy_paste" the data from one table to another, so it does not "auto increment" anything. There is no transformation going on. This is important to consider since it's a garbage_in-garbage_out script.
Your script at first glance looks good and you should test it on a test database. I have since dismantled my test database, and I didn't have any manufacturersto test it on to begin with anyway. If you do add it, I would add it to the products script since that's the natural location for it. Feel free to upload your first contribution if you do (hey, it's open source).
Albert
skipwater:
For my first post in this forum I just wanted to say Thanks Albert your code worked :smile:
With that said I was trying to modify your code to convert the manufacturer tables.
I got it to half work because I ran into manufacturer_id field which is an auto increment field.
The issue is that all the stores products have the manufacturer id in there record. So over the years adding and deleting manufacturers have left the osc manufacturer_id field non-sequential. So what I need is to convert the osc value in manufacturer_id field unchanged/raw.
I have posted the code that I am working on for reference. You might know the sql command that will allow the insert of the true value of manufacturer id and not the auto increment value.
Your help would be appreciated.
$connected = mysql_connect($source_db_host, $source_db_username, $source_db_password);
$dataopened = mysql_select_db($source_db);
if ($connected) {
echo "Connected Database Server<br>";
} else {
echo mysql_error();
exit;
}
if ($dataopened) {
echo "Database Opened<br><br><br>";
} else {
echo mysql_error();
exit;
}
// Get row id before insert Not used yet
function get_current_insert_id($zen_table)
{
$q = "SELECT LAST_INSERT_ID() FROM $zen_table";
return mysql_num_rows(mysql_query($q)) + 1;
}
$query_manufactures = "SELECT * FROM " . $source_db_table_prefix . "manufacturers";
$manufactures = mysql_query($query_manufactures);
$i = 0;
echo 'exporting manufactures ';
while ($export_record = mysql_fetch_assoc($manufactures)) {
$import_manufactures[$i]['manufacturers_id'] = $export_record['manufacturers_id'];
$import_manufactures[$i]['manufacturers_name'] = mysql_real_escape_string($export_record['manufacturers_name']);
$import_manufactures[$i]['manufacturers_image'] = $export_record['manufacturers_image'];
$import_manufactures[$i]['date_added'] = $export_record['date_added'];
$import_manufactures[$i]['last_modified'] = $export_record['last_modified'];
$i++;
echo 'GOod.';
}
mysql_free_result($manufactures);
echo '<br><br>';
$query_manufacturers_info = "SELECT * FROM " . $source_db_table_prefix . "manufacturers_info";
$manufacturers_info = mysql_query($query_manufacturers_info);
$i = 0;
echo 'exporting manufacturers info ';
while ($export_record = mysql_fetch_assoc($manufacturers_info)) {
$import_manufacturers_info[$i]['manufacturers_id'] = mysql_real_escape_string($export_record['manufacturers_id']);
$import_manufacturers_info[$i]['languages_id'] = mysql_real_escape_string($export_record['languages_id']);
$import_manufacturers_info[$i]['manufacturers_url'] = mysql_real_escape_string($export_record['manufacturers_url']);
$import_manufacturers_info[$i]['url_clicked'] = mysql_real_escape_string($export_record['url_clicked']);
$import_manufacturers_info[$i]['date_last_click'] = mysql_real_escape_string($export_record['date_last_click']);
$i++;
echo '.oO';
}
mysql_free_result($manufacturers_info);
echo '<br><br>';
mysql_close($connected);
$connected = mysql_connect($target_db_host, $target_db_username, $target_db_password);
$dataopened = mysql_select_db($target_db);
echo '<br><br>';
echo 'importing manufacturers <br>';
mysql_query("TRUNCATE " . $target_db_table_prefix . "manufacturers");
while (list($i, ) = each($import_manufactures)) {
$insert_manufacturers = "INSERT INTO " . $target_db_table_prefix . "manufacturers SET
manufacturers_id = '" . $import_manufacturers[$i]['manufacturers_id'] . "',
manufacturers_name = '" . $import_manufacturers[$i]['manufacturers_name'] . "',
manufacturers_image = '" . $import_manufacturers[$i]['manufacturers_image'] . "',
date_added = '" . $import_manufacturers[$i]['date_added'] . "',
last_modified = '" . $import_manufacturers[$i]['last_modified'] . "'
";
echo 'Insert record<br>';
$success = mysql_query($insert_manufacturers);
if (!$success) { echo mysql_error(); exit;}
echo 'Oo.';
}
echo '<br><br>';
echo 'clearing manufacturers_info';
echo '<br><br>';
mysql_query("TRUNCATE " . $target_db_table_prefix . "manufacturers_info");
echo 'importing manufacturers_info';
while (list($i, ) = each($import_manufacturers_info)) {
$insert_manufacturers_info = "INSERT INTO " . $target_db_table_prefix . "manufacturers_info SET
manufacturers_id = '" . $import_manufacturers_info[$i]['manufacturers_id'] . "',
languages_id = '" . $import_manufacturers_info[$i]['languages_id'] . "',
manufacturers_url = '" . $import_manufacturers_info[$i]['manufacturers_url'] . "',
url_clicked = '" . $import_manufacturers_info[$i]['url_clicked'] . "',
date_last_click = '" . $import_manufacturers_info[$i]['date_last_click'] . "'
";
$success = mysql_query($insert_manufacturers_info);
if (!$success) { echo mysql_error(); exit;}
echo '.';
}
echo '<br><br>';
echo '<br><br>';
mysql_close($connected);
echo '<br><br><br>All Done';
?>