waizrahman Posted June 14, 2017 Share Posted June 14, 2017 Hello i created db and tables in the main modules class and now i am looking to create objectmodel to use database functions, my question is that, can we create a database and table within objectmodel class in our module. or we can just create database functions thanks, Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted June 15, 2017 Share Posted June 15, 2017 Hi...First you need to create a database table in your module install method..Like as public function install() { if(!Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'table_name` (' . ' `id_table_name` INT(9) NOT NULL AUTO_INCREMENT,' . ' `your_table_fileds` VARCHAR(50) NOT NULL,' . ' PRIMARY KEY (`id_table_name`)' . ' ) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8;')) return false;} An then after you need put your class is "yourmodulename/classes/yourmoduleclass.php"see the here class yourmoduleclass extends ObjectModel { public $id_table_name; public $your_table_fileds; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'table_name', 'primary' => 'id_table_name', 'multilang' => false, 'fields' => array( 'your_table_fileds' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), ), ); } See other core classes of prestashop for your reference Thanks Link to comment Share on other sites More sharing options...
waizrahman Posted June 15, 2017 Author Share Posted June 15, 2017 (edited) thanks, so you want to say that we can not create database in objectmodel itself, it has to be in Install function ? JazakAllah Edited June 15, 2017 by waizrahman (see edit history) Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted June 15, 2017 Share Posted June 15, 2017 thanks, so you want to say that we can not create database in objectmodel itself, it has to be in Install function ? JazakAllah Hi.. ObjectModel is not create a database itself. first you need to create a your costume table on your module you need Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now