Problem:
Store setup was without database table prefix.
Now I need to move magento database to existing db with tables from another application.
Parameters:
Magento version 1.6.0
Solution:
Create script "add_db_prefix.php" in your store public catalog. Listing:
<?php
$database_host = "localhost"; // Here database server, ip or domain name
$database_user = "<your_db_user>";
$database_password = "<your_db_user_password>";
$magento_database = "<your_db_name>";
$table_prefix = "mage_"; // Table prefix wich you want!!!
$db = mysql_connect($database_host, $database_user, $database_password);
mysql_select_db($magento_database);
$result = mysql_query("SHOW TABLES") or die('Err');
while (($row = mysql_fetch_array($result)) != false) {
$old_table = $row[0];
if (preg_match('/'.$table_prefix.'/', $old_table)) {
echo "Table $old_table already done<br/>\n";
continue;
}
$new_table = $table_prefix.$old_table;
echo "Renaming $old_table to $new_table<br/>\n";
$query = "RENAME TABLE `$old_table` TO `$new_table`";
mysql_query($query);
}
?>
Do not forget change db conection data in script!
Follow to the url: http://<your_store_domain_name>/add_db_prefix.php
Now all tables in db with new prefix.
And of course you need setup table prefix in your store config file.
Edit config: "app/etc/local.xml"
Find string: "<table_prefix><![CDATA[]]></table_prefix>"
Put there your new table prefix: "<table_prefix><![CDATA[mage_]]></table_prefix>"
Store setup was without database table prefix.
Now I need to move magento database to existing db with tables from another application.
Parameters:
Magento version 1.6.0
Solution:
Create script "add_db_prefix.php" in your store public catalog. Listing:
<?php
$database_host = "localhost"; // Here database server, ip or domain name
$database_user = "<your_db_user>";
$database_password = "<your_db_user_password>";
$magento_database = "<your_db_name>";
$table_prefix = "mage_"; // Table prefix wich you want!!!
$db = mysql_connect($database_host, $database_user, $database_password);
mysql_select_db($magento_database);
$result = mysql_query("SHOW TABLES") or die('Err');
while (($row = mysql_fetch_array($result)) != false) {
$old_table = $row[0];
if (preg_match('/'.$table_prefix.'/', $old_table)) {
echo "Table $old_table already done<br/>\n";
continue;
}
$new_table = $table_prefix.$old_table;
echo "Renaming $old_table to $new_table<br/>\n";
$query = "RENAME TABLE `$old_table` TO `$new_table`";
mysql_query($query);
}
?>
Do not forget change db conection data in script!
Follow to the url: http://<your_store_domain_name>/add_db_prefix.php
Now all tables in db with new prefix.
And of course you need setup table prefix in your store config file.
Edit config: "app/etc/local.xml"
Find string: "<table_prefix><![CDATA[]]></table_prefix>"
Put there your new table prefix: "<table_prefix><![CDATA[mage_]]></table_prefix>"
Комментариев нет:
Отправить комментарий