PhpMadman Posted February 24, 2014 Share Posted February 24, 2014 (edited) Hi I'm working on a new module. At install it should create 3 tabels, but it doesn't and it does not give any error. I tested the actual mysql, and it's nothing wrong on it. and in the createTabels function i'm using &= with is a bitwise and, and as I understood it, it requires all of the $result to be true, to "return a true". If one is false, it will return false public function install() { if (parent::install() == false && $this->_createTabels() // Does not return error, does not create tabels && $this->_checkConfig() ) return false; return true; } private function _createTabels() { $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'pricefile_list` ( `id` int(10) NOT NULL AUTO_INCREMENT, `id_server` int(10) NOT NULL, `name` varchar(128) NOT NULL, `include` int(1) NOT NULL DEFAULT \'0\', `new` int(1) NOT NULL DEFAULT \'1\', `exclude` int(1) NOT NULL DEFAULT \'0\', PRIMARY KEY (`id`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'; $result &= Db::getInstance()->execute($sql); $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'pricefile_ids` ( `id` int(10) NOT NULL AUTO_INCREMENT, `id_server` int(10) NOT NULL, `id_client` int(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'; $result &= Db::getInstance()->execute($sql); $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'pricefile_indata` ( `id` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, `value` tinyint(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'; $result &= Db::getInstance()->execute($sql); $indata = array( 'name'=> 1, 'reference'=> 1, 'price_without_tax'=> 1, 'price_with_tax'=> 0, 'description'=> 1, 'description_short'=> 0, 'stock'=> 1, 'images'=> 0, ); foreach ($indata as $name => $value) $result &= Db::getInstance()->insert(_DB_PREFIX_.'pricefile_indata',array( 'name' => $name, 'value' => $value)); return $result; } Edited March 6, 2014 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted February 24, 2014 Share Posted February 24, 2014 public function install() { if (!parent::install()) return false: $this->_createTabels(); $this->_checkConfig(); return true; ) Hi, I updated this from original post... Link to comment Share on other sites More sharing options...
PhpMadman Posted February 25, 2014 Author Share Posted February 25, 2014 Hello. Thank you. Your post made me realize my error. This is what I have now. public function install() { if (!parent::install() || $this->_installDB() || $this->_populateDB() || $this->_checkConfig() ) return false; return true; } Link to comment Share on other sites More sharing options...
El Patron Posted February 25, 2014 Share Posted February 25, 2014 Hello. Thank you. Your post made me realize my error. This is what I have now. public function install() { if (!parent::install() || $this->_installDB() || $this->_populateDB() || $this->_checkConfig() ) return false; return true; } I like this better, mine was sort of thrown together in 12 seconds. Happy developing. Link to comment Share on other sites More sharing options...
PhpMadman Posted March 4, 2014 Author Share Posted March 4, 2014 This is the porper way to do it. All functions must return 1 or true, else it will report failed install. public function install() { if (!parent::install() || !$this->_installDB() || !$this->_populateDB() || !$this->_checkConfig() || !$this->registerHook('actionAdminControllerSetMedia') ) return false; return true; } 2 Link to comment Share on other sites More sharing options...
Recommended Posts