Page 1 of 1

database query in order_total-module not working

Posted: Wed Aug 20, 2025 9:17 am
by amaische
Hello,
i want to add the following database query to the function process in e.g. ot_shipping.php (includes/modules/order_total):
......
$lese_ab = $db->query(sprintf(<<<'EOSQL'
SELECT countries_iso_code_2 FROM countries WHERE countries_id = %d
EOSQL
, $order->billing['country_id']));

IF ($y_erg_ab = $lese_ab->fetch_assoc())
{
$y_iso = $y_erg_ab['countries_iso_code_2'];
}
.......
If i try the select in the database manually, there is one entry for countries_id=81.

If i run it in phoenix (page checkout_confirmation.php), the query does not work, and the checkout-page ist white and only shows "500 Internal Server Error".

What is the mistake ?

PHP Version : 7.4.33 (Zend 3.4.0), Phoenix: v1.0.9.7

best regards
Anke

Re: database query in order_total-module not working

Posted: Wed Aug 20, 2025 9:33 am
by Kofod95
I think your error_log would tell you that $db is not defined. Try $GLOBALS['db'] instead (or add it as a global after $order).

Best practice would be to make a new module with your changes, and install that instead of the core module.
Depending on what you want to do, there might also be other (better) ways to achieve that.

//Daniel

Re: database query in order_total-module not working

Posted: Wed Aug 20, 2025 9:49 am
by amaische
Dear Daniel,
thank you very much for your fast reply.
I change it to the "GLOBALS['db'] and everything is working :)
And yes, I had made a new module.
Anke