SELECT ... FOR UPDATE

Hi,

I am using mysql, and I want to use ‘SELECT … FOR UPDATE’ statement with findByPk for a transaction purpose. Is there any good way for it?

Thanks.

Hi , i face the same probleme .

I’m working on it and i 'll inform you if i find something.

if you have a solution too please share it with me

That code work’s fine for me ;)

hope it’s may help





$connection = Yii::app()->db;   // assuming you have configured a "db" connection

$transaction = $connection->beginTransaction();

try {

	$client = Client::model()->findBySql("

					SELECT *  

					FROM client WHERE is_payed = 0 

					LIMIT 0,35 FOR UPDATE;

					");

	$client->is_payed = 1;

	$client->update();

	$transaction->commit();

} catch (Exception $e) {

	$transaction->rollBack();

	Yii::app()->user->setFlash('error', "database error");

	$client =null;

}

return $client ;