Symfony2保存错误的数据

时间:2012-07-23 18:29:02

标签: php database symfony doctrine

我很难保存多条记录

我创建了一个创建值数组的算法,然后循环遍历数组并保存更新后的数据x,y。但是对于一些未知的原因,我希望y = 0;只有1-5显示我所期望的。

这是我的代码:

foreach($line as $row){
  if(array_key_exists('id',$row)){
    $region = $em->getRepository("Bundle:Something\\Region")
            ->find($row['id']);
    if (!$region) {
      throw $this->createNotFoundException('No product found for id '.$row['id']);
    }

    $region->setX($row['posX']);
    $region->setY($row['posY']);
    if($row['posY'] == 0){
      error_log("se agrego id: " . $row['id'] . " con y: " . $row['posY']);
      error_log("id actual: " . $region->getId() . "con y: " . $region->getY());
    }
    em->persist($region);
    $em->flush();
    $em->clear();
    unset($region);

这是我的输出

se agrego id: 1508 con y: 0
id actual: 1508con y: 0
se agrego id: 1931 con y: 0
id actual: 1931con y: 0
se agrego id: 1754 con y: 0
id actual: 1754con y: 0
se agrego id: 1907 con y: 0
id actual: 1907con y: 0
se agrego id: 1641 con y: 0
id actual: 1641con y: 0
se agrego id: 1677 con y: 0
id actual: 1677con y: 0
se agrego id: 1692 con y: 0
id actual: 1692con y: 0
se agrego id: 1578 con y: 0
id actual: 1578con y: 0
se agrego id: 1326 con y: 0
id actual: 1326con y: 0
se agrego id: 1636 con y: 0
id actual: 1636con y: 0
se agrego id: 1637 con y: 0
id actual: 1637con y: 0
se agrego id: 1359 con y: 0
id actual: 1359con y: 0
se agrego id: 1892 con y: 0
id actual: 1892con y: 0
se agrego id: 1324 con y: 0
id actual: 1324con y: 0
se agrego id: 1773 con y: 0
id actual: 1773con y: 0
se agrego id: 1581 con y: 0
id actual: 1581con y: 0
se agrego id: 1538 con y: 0
id actual: 1538con y: 0
se agrego id: 1745 con y: 0
id actual: 1745con y: 0
se agrego id: 1925 con y: 0
id actual: 1925con y: 0
se agrego id: 1564 con y: 0
id actual: 1564con y: 0
se agrego id: 1648 con y: 0
id actual: 1648con y: 0

在坚持和冲洗之前,一切似乎都是正常的

然后我检查数据库,我看到了这个

select * from regions where y = 0;
id  | field | field |  x  | y | field | field |       field       | field  | field |      createdat      |      updatedat      | field 
------+---------+---------+-----+---+-------+--------+-------------------+---------+----       ----+---------------------+---------------------+--------------
 1324 |       1 |      58 | 640 | 0 |    24 |     24 | 4fe49d9fddebb.jpg | running |        2 | 2012-06-22 10:29:01 | 2012-07-23 12:13:01 |          118
 1677 |       1 |      58 | 280 | 0 |    40 |     40 | 4fe4e48693650.png | running |       1 | 2012-06-22 15:31:11 | 2012-07-23 12:13:01 |          342
 1508 |       1 |      58 |   0 | 0 |    48 |     16 | 4fe4bfcf58560.jpg | running |      1 | 2012-06-22 12:54:43 | 2012-07-23 12:13:01 |          212
 1565 |       1 |      58 | 272 | 0 |    16 |     16 | 4fe4ce3d9e61c.jpg | running |      0 | 2012-06-22 13:56:18 | 2012-07-23 11:49:14 |          245
 1655 |       1 |      58 | 816 | 0 |    40 |     48 | 4fe4ded96e9be.png | running |      3 | 2012-06-22 15:07:00 | 2012-07-23 11:49:14 |          325
(5 rows)

只有5行,y = 0,这是错误的

然后我去了日志,我看到了这个

parameters: $1 = '1636' 
.....
2012-07-23 13:49:17 EDT LOG:  duration: 0.022 ms  bind pdo_stmt_000002b8: UPDATE regions    SET x = $1, y = $2, updatedAt = $3 WHERE id = $4
**2012-07-23 13:49:17 **EDT DETAIL:  parameters: $1 = '5048', $2 = '40', $3 = '2012-07-23 11:49:17', $4 = '1636'
2012-07-23 13:49:17 EDT LOG:  execute pdo_stmt_000002b8: UPDATE regions SET x = $1, y = $2, updatedAt = $3 WHERE id = $4
2012-07-23 13:49:17 EDT DETAIL:  parameters: $1 = '5048', $2 = '40', $3 = '2012-07-23 11:49:17', $4 = '1636'****
2012-07-23 13:49:17 EDT LOG:  duration: 0.123 ms
2012-07-23 13:49:17 EDT LOG:  duration: 0.030 ms  statement: DEALLOCATE    pdo_stmt_000002b8
2012-07-23 13:49:17 EDT LOG:  duration: 3.578 ms  statement: COMMIT

任何想法都在这里?

0 个答案:

没有答案
相关问题