Php 更新时的奇怪行为

Php 更新时的奇怪行为,php,doctrine,Php,Doctrine,我有一个简单的表格,如下所示: class SnookerCurrentInfo extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('current_frame_id', 'integer', 4, array('notnull' => 'false')); $this->hasColumn('current_player_id', 'i

我有一个简单的表格,如下所示:

class SnookerCurrentInfo extends Doctrine_Record 
{
  public function setTableDefinition() 
  {
    $this->hasColumn('current_frame_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_player_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score1', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score2', 'integer', 4, array('notnull' => 'false'));
  }

  public function setUp()
  {
    $this->setTableName('snooker_current_info');
  }
}
$info = Doctrine::getTable('SnookerCurrentInfo')->find(1);

$info->current_frame_id = $jsonInfo['current_frame_id'];
$info->current_player_id = $jsonInfo['current_player_id'];
$info->current_score1 = $jsonInfo['current_score1'];
$info->current_score2 = $jsonInfo['current_score2'];

$info->save();
我想在这个表中只保留一个条目。因此,每次更改值时,我都会读取id=1的条目,然后更改对象并执行save。例如:

class SnookerCurrentInfo extends Doctrine_Record 
{
  public function setTableDefinition() 
  {
    $this->hasColumn('current_frame_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_player_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score1', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score2', 'integer', 4, array('notnull' => 'false'));
  }

  public function setUp()
  {
    $this->setTableName('snooker_current_info');
  }
}
$info = Doctrine::getTable('SnookerCurrentInfo')->find(1);

$info->current_frame_id = $jsonInfo['current_frame_id'];
$info->current_player_id = $jsonInfo['current_player_id'];
$info->current_score1 = $jsonInfo['current_score1'];
$info->current_score2 = $jsonInfo['current_score2'];

$info->save();
但奇怪的是,我试图弄清楚。首先,假设条目是(30,1,1,0),我切换播放器,所以将条目更新为(30,2,1,0)。我再次切换播放器,因此条目应该更新为(30,1,1,0),但这不会影响数据库!!在数据库中,条目仍然保持为(30,2,1,0)

但是如果在(30,2,1,0)之后,我将分数更新为(30,2,1,1),然后将玩家切换回(30,1,1,1),那么这就可以了

那是什么?我该如何处理它?

您是否尝试过使用而不是保存

另一种可以节省开支但可能更符合您需要的方法是

 $info->replace();
而不是save()

您是否尝试过使用而不是保存

另一种可以节省开支但可能更符合您需要的方法是

 $info->replace();

而不是save()

我意识到这个问题很老了,但也许这会帮助其他人

在检查脏字段时,Doctrine 1.x(也可能是2.x)似乎在布尔值方面存在一些问题。我已经有一段时间没有使用1.x了,但是尝试将值从(int)1更新为0是行不通的,它无法识别更改(我猜是关于true/false的)


我最后做的是在坚持更改之前用(字符串)0替换每个(int)0。

我意识到这个问题已经很老了,但这可能会帮助其他人

在检查脏字段时,Doctrine 1.x(也可能是2.x)似乎在布尔值方面存在一些问题。我已经有一段时间没有使用1.x了,但是尝试将值从(int)1更新为0是行不通的,它无法识别更改(我猜是关于true/false的)


我最后做的是在保留更改之前,将每个(int)0替换为(string)0。

谢谢,Drgorosos。我尝试过更新和替换,它们的作用与保存相同。我想如果保存对象是save,save也会更新,不是吗?谢谢,drgorosos。我尝试过更新和替换,它们的作用与保存相同。我想如果是save对象,save也会更新,不是吗?