module_developer Posted May 17, 2013 Share Posted May 17, 2013 Hi, I am really newbie to the prestashop modules. In my module I have used this code for install public function install() { if (!parent::install() || !$this->installDB() || !$this->registerHook('leftColumn') || !$this->registerHook('rightColumn')) return false; return true; } and in installDB function I am creating a database table. So the code for that function is like this public function installDB() { DB::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'socialblock` ( `app_id` int(10) unsigned NOT NULL auto_increment, `app_name` varchar(255) NOT NULL, `status` int(2) NOT NULL, `title` varchar(255) NOT NULL, PRIMARY KEY (`app_id`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); return true; } Here its working fine. When the module is installing it is creating the table. Now i want that when the table will be created after that some values will be added to the table. The values which will be inserted will be like this DB::getInstance()->Execute(' INSERT INTO TABLE `'._DB_PREFIX_.'socialblock` ( `app_id`, `app_name`, `status`, `title`) VALUES ('1', 'google plus', 0, 'google title'), ('', 'facebook', 0, 'google title'), ('', 'twitter', 0, 'google title'), ('', 'pintrest', 0, 'google title');'); So can someone kindly tell me what will be the good procedure to do this? Any help and suggestions will be really appreciable. Thanks Link to comment Share on other sites More sharing options...
kadziola.jarek Posted May 17, 2013 Share Posted May 17, 2013 Install sql code should be in one request. Merge this codes. Link to comment Share on other sites More sharing options...
module_developer Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) @kadziola.jarek thanks for the reply but can you give me example for the code which I have used in my post? When I used one request for creating table and inserting values it showed an error like Parse error: syntax error, unexpected T_STRING in line 10(INSERT INTO `'._DB_PREFIX_.'socialblock` ) public function installDB() { DB::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'socialblock` ( `app_id` int(10) unsigned NOT NULL auto_increment, `app_name` varchar(255) NOT NULL, `status` int(2) NOT NULL, `title` varchar(255) NOT NULL, PRIMARY KEY (`app_id`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); DB::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'socialblock` (`app_id`, `app_name`, `status`, `title`) VALUES (1, 'google plus', 0, 'google title'),(2, 'facebook', 1, 'facebook title');'); return true; } Edited May 17, 2013 by module_developer (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts