Using the database class to save comments

We will now register the comment and grade filled in by the visitor in the database. First, we will create a table in our database:

CREATE TABLE IF NOT EXISTS ps_mymod_comment (id_mymod_comment int(11) NOT NULL AUTO_INCREMENT, id_product` int(11) NOT NULL, grade tinyint(1) NOT NULL, comment text NOT NULL,date_add datetime NOT NULL,PRIMARY KEY (id_mymod_comment)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

As you can see, the table contains five fields: the line identifier (in auto-increment), the product identifier, the grade, the comment, and the date of the comment.

Note

In PrestaShop, the naming conventions for the database field are:

  • Name your identifier field with the id_ prefix followed by the ...

Get PrestaShop Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.