uniline1 Posted August 13, 2012 Share Posted August 13, 2012 I'm working through the tutorial about how to create a PrestaShop module, when it says (here): Follow these steps: 1. Add a new table to your PrestaShop database, named ps_test. However, for the life of me I can't find the instructions on how to "Add a new table to your PrestaShop database". I know it's probably simple but I can't find it. Can anyone help? Link to comment Share on other sites More sharing options...
bellini13 Posted August 13, 2012 Share Posted August 13, 2012 assuming you are using mysql for your database, then you should have access to phpmyadmin from your admin area/cpanel. If not, then you will need to use a sql client to access your database, and issue a create table statement. Link to comment Share on other sites More sharing options...
uniline1 Posted August 13, 2012 Author Share Posted August 13, 2012 Yes, that's got it, thanks. I didn't realize it was done outside of PrestaShop. Link to comment Share on other sites More sharing options...
bellini13 Posted August 13, 2012 Share Posted August 13, 2012 note: when you create a real module, you will create the table using php code from within the modules install function, so that users of the module would not have to manually create the table Link to comment Share on other sites More sharing options...
uniline1 Posted October 19, 2012 Author Share Posted October 19, 2012 note: when you create a real module, you will create the table using php code from within the modules install function, so that users of the module would not have to manually create the table Ok, I don't see that in the tutorial. Is that a Db::getInstance()->Execute() command or which command do you use to create the table? Link to comment Share on other sites More sharing options...
bellini13 Posted October 19, 2012 Share Posted October 19, 2012 you can review other modules that come with prestashop, so you can repeat how its done. Link to comment Share on other sites More sharing options...
sharif854 Posted October 20, 2012 Share Posted October 20, 2012 you can use php code like this code: $sql= "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."tablename`( `id_tablename` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR(256) NOT NULL )"; if(!$result=Db::getInstance()->Execute($sql)) return false; look this code : 1. there is better to use id_tablename instead of id in your table this is use in adminTab module 2.you use Execute when you wnat to write in database like create delete update and... and use ExecuteS when you want to read database like select and when you use ExecuteS use _PS_USE_SQL_SLAVE_ like this : Db;;getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql) for this section you go to this link for know how to work the sql in prestashop good practice 4 Link to comment Share on other sites More sharing options...
uniline1 Posted October 20, 2012 Author Share Posted October 20, 2012 Perfect, thanks. I've experimented with phpAdmin commands so I can see how this fits right in, but in the php code. Link to comment Share on other sites More sharing options...
sancoLgates Posted January 12, 2015 Share Posted January 12, 2015 Perfect, thanks. I've experimented with phpAdmin commands so I can see how this fits right in, but in the php code. you can use this in php code type 'module' public function installDB() { return Db::getInstance()->execute(' CREATE TABLE `'._DB_PREFIX_.'test` `id_test` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id_test`) ) DEFAULT CHARSET=utf8;'); } Link to comment Share on other sites More sharing options...
beginner1 Posted November 3, 2017 Share Posted November 3, 2017 On 1/12/2015 at 8:59 AM, sancoLgates said: you can use this in php code type 'module' public function installDB() { return Db::getInstance()->execute(' CREATE TABLE `'._DB_PREFIX_.'test` `id_test` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id_test`) ) DEFAULT CHARSET=utf8;'); } I know this thread is very old but I just saw it and there's a question I want to ask. What is _DB_PREFIX_? Is this the prestashop database? Link to comment Share on other sites More sharing options...
bellini13 Posted November 3, 2017 Share Posted November 3, 2017 6 hours ago, beginner1 said: What is _DB_PREFIX_? Is this the prestashop database? This is the prefix to the name of your database. The value is typically ps_ The prefix allows you to share a single database across multiple stores, where each store will have a different prefix (ps1_, ps2_, ps3_ etc...) 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