This post is automatically translated to English by Google Translate.

Lock tables in CakePHP

I needed to do some table locking. Just call the method from the controller to lock and unlock your tables. The code below is only tested with MySQL and InnoDb tables. Put it in app_model.php

{code }


class AppModel extends Model {

    function lockTableRW() {




    function lockTable($type='READ') {

$dbo = $this->getDataSource();

$dbo->execute('LOCK TABLES '.$this->table.' '.$type);


    function unlockTables() {

$dbo = $this->getDataSource();

$dbo->execute('UNLOCK TABLES');





Posted in CakePHP

Leave a Reply

Your email address will not be published. Required fields are marked *