Magento : Make Changes To Core Config Data Programmatically

Below Magento snippet is used to add/update changes to core_config_data database table.
To update Magento system configuration data for single value/field/column, you can use following custom PHP script:
<?php
define('MAGENTO_ROOT', getcwd());
require_once MAGENTO_ROOT.'/app/Mage.php';
umask(0);
Mage::app('admin')->setUseSessionInUrl(false);
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
error_reporting(E_ALL);

try {
    Mage::getConfig()->init();
    Mage::app();
} catch (Exception $e) {
    Mage::printException($e);
}

$readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$writeAdapter = Mage::getSingleton('core/resource')->getConnection('core_write');
$valueToUpdate = 'testTitle'; // It may be direct integer or any varchar depends on your need
//You just need to update the query part in like "section/group/field".
// You can get this either from database table column "path" in core_config_data or from system configuration of admin by inspecting elements from browser.
$query = "SELECT config_id FROM `core_config_data` WHERE `path` LIKE '%design/head/default_title%'";
$result = $readAdapter->fetchOne($query);
$writeAdapter->update(
    "core_config_data",
    array("value" => $valueToUpdate),
    "config_id=$result"
);
?>

Leave a Reply