Preyos Posted September 14, 2014 Share Posted September 14, 2014 Hi all, I work on a module, and I have to run sql command, but it won't work. Here is my code: public function hookActionPaymentConfirmation($params) { $id_order = $params['id_order']; $sqlSearchProd = 'SELECT id_product FROM ‘'._DB_PREFIX_.'order_detail’ WHERE id_order='.$id_order; $id_product = Db::getInstance()->ExecuteS($sqlSearchProd); foreach ($id_product as $id_product) { $sqlSelectPric = 'SELECT price FROM ‘'._DB_PREFIX_.'product’ WHERE id_product='.$id_product; $price = Db::getInstance()->ExecuteS($sqlSelectPric); ..... } I update an order to "Accepted Payement". I activated the fulllog in mysql and a cat mysql.log | grep id_product= return nothing. So the foreach has not been executed... Do you have any idea ? Thank you in advance, Alexandre Link to comment Share on other sites More sharing options...
musicmaster Posted September 14, 2014 Share Posted September 14, 2014 I don't know what to think of this code: foreach ($id_product as $id_product) I have never tried something like that and would expect that it will overwrite $id_product I would suggest writing an print_r($id_product) immediately after the sql command to see what is in the variable. Link to comment Share on other sites More sharing options...
Preyos Posted September 15, 2014 Author Share Posted September 15, 2014 (edited) Hi, Thank you for your response I don't know about the foreach, but, in doubt, here is my code: $id_order = $params['id_order']; $sqlSearchProd = 'SELECT id_product FROM ‘'._DB_PREFIX_.'order_detail’ WHERE id_order='.$id_order; $id_prod = Db::getInstance()->ExecuteS($sqlSearchProd); d($id_prod); foreach ($id_prod as $id_product) { $sqlSelectPric = 'SELECT price FROM ‘'._DB_PREFIX_.'product’ WHERE id_product='.$id_product; $price = Db::getInstance()->ExecuteS($sqlSelectPric); ... } And the die return END The SQL command was not executed... I don't understand... Alexandre Edited September 15, 2014 by Preyos (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted September 15, 2014 Share Posted September 15, 2014 Can you try with a simplified query whether queries can be made at all here?: $sqlSearchProd = 'SELECT id_product FROM ‘'._DB_PREFIX_.'product’'; Can you also check with some debug code that $id_order has a valid value? Link to comment Share on other sites More sharing options...
PhpMadman Posted September 15, 2014 Share Posted September 15, 2014 I recomend doing a p($sqlSearchProd) Then you will see if something is missing, and you can also try to run it manually to check if there are any errors in code. Also you don't seem to use the correct sign (`) around the ._DB_PREFIX_.'order_detail. and in order_detail it's product_id and not id_product for some reason. Link to comment Share on other sites More sharing options...
Preyos Posted September 16, 2014 Author Share Posted September 16, 2014 Hi, Thank you both for your response, I'm an idiot, in ps_order_detail, it's product_id abnd not id-product... Tank you very much again for your help Alexandre Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now