Welcome Guest, Not a member yet? Register   Sign In
How to run Transactions in controller?
#5

(04-06-2021, 09:44 AM)mlurie Wrote: Add this to your BaseController in the "Preload" section of the initController method:

PHP Code:
$this->db = \Config\Database::connect(); //Load database connection 

You should then be able to use transactions in any Controller like this:

PHP Code:
$this->db->transStart(); //Begin database transaction
$this->db->transComplete(); //Complete database transaction 

Creating the object in the BaseController has been deprecated.  Use this instead in your model or controller:

PHP Code:
$db = \Config\Database::connect(); //Load database connection

$db->transStart(); //Begin database transaction
$db->transComplete(); //Complete database transaction 
Reply


Messages In This Thread
RE: How to run Transactions in controller? - by mlurie - 01-09-2023, 07:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB