【问题标题】:Phalcon transaction not working correctPhalcon 事务无法正常工作
【发布时间】:2016-06-20 13:03:02
【问题描述】:

我创建了这样的交易:

$this->db->begin();
$topic = new Topic();
$topic->assign( $data );
$topic->save();

var_dump( $this->db->isUnderTransaction() ); // bool(true)

$this->db->rollback();

var_dump( $this->db->isUnderTransaction() ); // bool(false)

但是,数据库仍然更改并插入了新行。回滚方法不起作用。

【问题讨论】:

    标签: mysql database transactions phalcon


    【解决方案1】:

    $di->set 方法只有在第二个参数为“TRUE”时才被共享。

    $di->set( 'db', function() use( $conf ) {
        return new DbAdapter( [
            'host' => $conf->db->host,
            'username' => $conf->db->username,
            'password' => $conf->db->password,
            'dbname' => $conf->db->dbname,
            'options' => [
                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_PERSISTENT => true
            ]
        ] );
    }, true );
    

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 2014-07-10
      • 2015-04-20
      • 1970-01-01
      相关资源
      最近更新 更多