Question

Install and upgrade script will often have these calls in them:

$this->startSetup();

$this->endSetup();

I know they are not required due to me not using them for several such scripts. Can anyone explain their purpose and if there are any implications to using/not using them?

Was it helpful?

Solution

If you peek at Varien_Db_Adapter_Pdo_Mysql (I got there by looking into Mage_Core_Model_Resource_Setup which does getConnection()->startSetup()) you'll see that this call does some database-specific prepping:

public function startSetup()
{
    $this->raw_query("SET SQL_MODE=''");
    $this->raw_query("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");
    $this->raw_query("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
    return $this;
}

public function endSetup()
{
    $this->raw_query("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
    $this->raw_query("SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS=0, 0, 1)");
    return $this;
}

Basically most of these are for compatibility and some of them speed up a few operations (for example disabling the foreign key checks).

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top