how to update database in prestashop 1.5

67 views Asked by At

Am currently developing a PrestaShop payment module and am having issues updating a custom column in the database

$sql = 'UPDATE `'._DB_PREFIX_.'Webpay_transactions` 
     SET `Customer_id` = '.(int)$customer->id.', 
         `ResponseCode`= '.pSQL($responsecode).',
         `ResponseDescription`='.pSQL($desc).',
         `ApprovedAmount`= '.(int)$transamount.',
         `ReturnedReference`= '.pSQL($retRef).',
         `CardNumber`='.(int)$cardNum.',
         `Order_reference`= '.(int)$this->module->currentOrder.'
         WHERE `TransactionRef` = '.(int)$txn_ref.'';
Db::getInstance()->execute($sql);
1

There are 1 answers

0
chibuzor Enukoha On

OK, I figured out where the issue was coming from. the TransactionRef variable had special characters which were not proper;y escaped. I had to do some fact finding and I finally found a solution.

$txn_ref = "TXN|EDUCON|798004|6|131"

 Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'Webpay_transactions` 
            set Customer_id =\''.(int)$customer->id.'\', 
                ResponseCode = \''.pSQL($responsecode).'\',
                ResponseDescription = \''.pSQL($desc).'\',
                ApprovedAmount = \''.(int)$transamount.'\',
                ReturnedReference = \''.pSQL($retRef).'\',
                CardNumber = \''.(int)$cardNum.'\',
                Order_reference = \''.(int)$this->module->currentOrder.'\'

            WHERE TransactionRef = \''.pSQL($txn_ref).'\'');