Child pages
  • DB class best practices

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: I wonder what the author's native language would be ^^

...

Tip

You should use insert(), update() et and delete() as much as possible, and only use execute() if the query gets too complex.
Please note that this method returns a boolean value (true or false), not a database resource that can then be used.

...

Code Block
$sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'shop';
$totalShop = Db::getInstance()->getValue($sql);
Note

getValue() does not protect your code from hacking attempts (SQL injections, XSS flaws and CRSF breaches). You still have to secure your data yourself.
One PrestaShop-specific securization method is pSQL($value): it helps protect your database against SQL injections.

NumRows()

This method caches and returns the number of results from the most recent SQL query;

...