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

Php 有没有办法使用Db实例在prestashop中准备sql语句?,php,mysql,prepared-statement,prestashop,prestashop-1.6,Php,Mysql,Prepared Statement,Prestashop,Prestashop 1.6,我想找到类似PDO方法的东西,它可以与Prestashop DB对象、模块或使用PDO类并在执行前准备语句的新类一起工作 如果我可以用PDO类更改以下内容 $result = Db::getIntance()->executeS('SELECT * FROM customer WHERE id = '.$id_customer); 我没有看到任何类似的情况,我想知道在不使用prepare语句生成更多代码之前是否存在这种情况您可以使用DbQuery类生成更干净的代码 $sql = new

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

如果我可以用PDO类更改以下内容

$result = Db::getIntance()->executeS('SELECT * FROM customer WHERE id = '.$id_customer);
我没有看到任何类似的情况,我想知道在不使用prepare语句生成更多代码之前是否存在这种情况

您可以使用DbQuery类生成更干净的代码

$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),
));

你为什么需要这个?不管怎样,如果没有它,它工作得很好。准备好的语句主要用于避免SQL注入。如果查询中有参数,就没有理由不使用它。