有没有办法使用 Db 实例在 prestashop 中准备 sql 语句?

Is there a way to prepare a sql statement in prestashop using Db instance?

我想找到类似 PDO 方法的东西,它与 Prestashop DB 对象一起工作,或者一个模块,或者使用 PDO class 的新 class 并在执行前准备语句。

如果我可以通过 PDO 更改以下内容 class

$result = Db::getIntance()->executeS('SELECT * FROM customer WHERE id = '.$id_customer);

我没有看到类似的东西,我想知道是否存在,然后再编写更多没有准备语句的代码

您可以使用 DbQuery class 以获得更清晰的代码

$sql = new DbQuery();
//this line is optional
$sql->select('*');
//PrestaShop will add the prefix to the table
$sql->from('customer');
//or if you want to select specific columns
$sql->select('id_customer, name, etc..');
//each where line is considered as an AND
$sql->where('id = '.(int)$id_customer);
$sql->where('name = '.pSQL('name of customer'));
$result = Db::getIntance()->executeS($sql);

在 prestashop 中你可以像这样使用 ORM

Db::getInstance()->insert('target_table', array(
'id_target' => (int)$target,
'name'      => pSQL($name),
));