I am creating a script for PrestaShop 1.6 that inserts data into a table. My table is made in this way:
As I enter a description I would get back the ID value.
On can not use the standard because it blocked by PrestaShop.
I find this a situation:
$sql = "INSERT INTO `"._DB_PREFIX_."table`(`desc`) VALUES ('".$this->desc."')";
$restpo = Db::getInstance()->execute($sql);
var_dump($restpo);
But I have an answer only a boolean. Can you suggest something?
You can use the:
$id = (int)Db::getInstance()->Insert_ID();
For example, in the Cart class:
$last_id = (int)Db::getInstance()->Insert_ID();
I also recommend the use of the function insert, for example in the Carrier class:
$values = array();
foreach ($shops as $id_shop) {
$values[] = array(
'id_carrier' => (int)$this->id,
'id_tax_rules_group' => (int)$id_tax_rules_group,
'id_shop' => (int)$id_shop,
);
}
$res = Db::getInstance()->insert('carrier_tax_rules_group_shop', $values);
Then use the Insert_ID to get the last one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With