We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

inserting muliple record in transaction in webapi of phalcon

here is my scheme i want to insert multiple orderdetail against 1 order in 1 time.

order (id,customer_id,phone,address,total,created_date) orderdetails(id,order_id,inventory_id,quantity,amount,created_date)

thats how i am doing but it is giving me error....

try {

                $manager     = new TxManager();

                // Request a transaction

                $transaction = $manager->get();

                $order=new order();

                $order->setTransaction($transaction);

                // assign values to properties

                $order->id="160912-170200-9876";

                $order->customer_id=26535;

                $order->phone="2443434";

                $order->total=219.00;

                if ($order->save() == false) {

                $transaction->rollback("Cannot save robot part");

                echo json_encode(array('status'=>'501','message'=>"error in saving order sum"));

                }

                $orderdetails=new orderdetails();

                $orderdetails->setTransaction($transaction);

                //assign values

                $orderdetails->inventory_id =2;

                $orderdetails->quantity=1;

                $orderdetails->amount=199.00;

                $orderdetails->order_id="160912-170200-9876";

                if ($orderdetails->save() == false) {

                $transaction->rollback("Cannot save robot part");

                }

                $transaction->commit();

                echo json_encode(array('status'=>'1','message'=>"success"));
            }
            catch (TxFailed $e) {
                echo json_encode(array('status'=>'501','message'=>'orders failed because '.$e->getMessage()));
            }

Could you provide an error?



1.6k

Unexpected 'C'

Could you provide an error?