Welcome Guest, Not a member yet? Register   Sign In
How can I work with transactions with the CodeIgniter Query Builder?
#1

How can I work with transactions with the CodeIgniter Query Builder?
Reply
#2

Please READ:
CodeIgniter 4 Users Guide -> Working with Databases Transactions
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(07-29-2023, 10:29 PM)InsiteFX Wrote: Please READ:
CodeIgniter 4 Users Guide -> Working with Databases Transactions

In the examples use the DB_Connect function within the transactions. My question is if I put Query Builder inside the transactions work?
Reply
#4

Transaction code is here:

system/Database/BaseConnection.php

It's in the BaseConnection so I would think that it should work with QueryBuilder.
But all examples that I have seen only use the db->query().

Here is a CodeIgniter 4 Example on using the db->query() methods.

CodeIgniter 4 Transaction Example
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(07-30-2023, 10:56 PM)InsiteFX Wrote: It's in the BaseConnection so I would think that it should work with QueryBuilder.

I'm need use transaction for payment mechanism, if u say Query Builder should work, then i can write somethink like this?:
PHP Code:
...
$this->db->transStart();
model(PaymentModel::class)->update(['status'=>1], ['id'$payment_id]);
model(UserModel::class)->update(['balance'=>'balance+'.$payment_amount], ['id'$user_id]);
$this->db->transComplete(); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB