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

ORM with Master - Slave mysql database in phalcon

Hi, guys! I am confuse in phalcon create function with two database.

This is my database environment. -> database - master(write), database -slave(read)

Here is what i need !!

After I create a row data, I need to get update time and create time.

Here is my code =>

$car = new Car();
$data['OwnerName'] = 'Peter';
$car->create($data);
$car->refresh();
var_export( $car->toArray());

I said that i have two database to read and write at begining.

Therefore, i will get this ouput ->

[
    'carId' => 1,
    'OwnerName' => 'Peter',
    'updateTIme' => NULL,
    'createTime'   => NULL

]

Actually, I found i add a transaction in this create processing can solve this problem as belows.

However, i have no idea to know how it work! Have anyone can explain it ?

$transaction = (new mode())->getTransaction();
$car = new Car();
$car->setTransaction();
$data['OwnerName'] = 'Peter';
$car->create($data);
$car->refresh();
var_export( $car->toArray());
$transaction->commit;

[
    'carId' => 1,
    'OwnerName' => 'Peter',
    'updateTIme' => '2018-12-25 11:11:11',
    'createTime'   => '2018-12-25 11:11:11'
]