database query in order_total-module not working

Open to all! Ask other shopowners for help.
Post Reply
amaische
Member
Posts: 13
Joined: Wed Aug 18, 2021 7:10 am
Phoenix Version: v1.0.9.7
Been thanked: 1 time

database query in order_total-module not working

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: database query in order_total-module not working

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
amaische
Member
Posts: 13
Joined: Wed Aug 18, 2021 7:10 am
Phoenix Version: v1.0.9.7
Been thanked: 1 time

Re: database query in order_total-module not working

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply