Table of content
Table of Contents | ||||||
---|---|---|---|---|---|---|
|
DB class best practices
Most of the time, creating a module or overriding PrestaShop means using or inserting data in the database. Knowing how to properly use the DB core class is therefore mandatory for developers. Besides providing you with an abstraction for other potential database system, the DB class offers several tools to make your life easier.
...
Parameter | Description |
---|---|
$table | Table's name. The PrestaShop prefix is automatically inserted, you do not have to put it in. |
$data | The data array, containing the data to be inserted, with name as keys and data as values. |
$null_values | If |
$use_cache | If |
$type | If you wish to change the insertion, this parameter can take the following constants: |
$add_prefix | If |
...
update()
Methode signature: update($table, $data, $where = '', $limit = 0, $null_values = false, $use_cache = true, $add_prefix = true)
Cette méthode s’utilise de la même façon que la méthode insert(), mais pour les mises à jour de données (requêtes UPDATE). Les arguments étant principalement les même, voici juste une description des deux qui diffèrent :
- $where : prend la clause WHERE pour la mise à jour
- $limit : vous pouvez limiter le nombre de résultats que vous mettrez à jour
($table, $data, $null_values = false, $use_cache = true, $type = Db::INSERT, $add_prefix = true)
This method works as the insert()
method does, but for data update (UPDATE
queries). Both have roughly the same parameters, with type
gone and these two additions:
Parameter | Description |
---|---|
$where | Takes the update's |
$limit | You can limit the number of results that you will update. |
La méthode delete($table, $where = '', $limit = 0, $use_cache = true, $add_prefix = true)
...