doctrine - Symfony2 Doctrine

标签 doctrine symfony

我尝试使用

进行数据库查询
$position = $repository->findBy(
    array('id' => $profileId,'datum' => '10.07.2011'),
    array('timestamp', 'DESC')
);

数据库看起来像

id  haveInCircles   inOtherCircles  datum   timestamp
1   24  14  11.07.2011  1310403840
1   20  10  10.07.2011  1310317440
1   10  5   09.07.2011  1310317440
1   25  17  12.07.2011  1310468838

我得到的结果总是最后一天的数据入库。在本例中为“12.07.2011”。

最佳答案

对日期使用 varchar 可能是最糟糕的方法。将数据字段更改为日期或日期时间,相应地更改您的模型,使 Doctrine 字段为日期,然后执行以下操作:

$position = $repository->findBy(
    array('id' => $profileId,'datum' => new Datetime('2011-07-10')),
    array('timestamp' => 'DESC')
);

http://www.php.net/manual/en/datetime.construct.php

我建议复习的模式实践简介: http://brixican.blogspot.ca/2011/04/5-mysql-best-practices-when-designing.html

关于doctrine - Symfony2 Doctrine ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6663988/

相关文章:

php - Doctrine 中的两个生成值

php - 从 Doctrine 2 的存储库中选择特定列

php - Symfony 4、Doctrine 和 AWS RDS 只读副本使用

php - symfony Doctrine 类型日期时间预期格式 y-m-d h :i:s

php - 使用 DoctrineExtensions Translatable Symfony2 的数据库查询太多

symfony - 在 SF3.4 及更高版本中运行 Symfony DIC 烟雾测试

symfony - 并行运行行为测试(在两个浏览器窗口中)

symfony - 在 Sylius 中更新供应商 - 想象捆绑错误 (Symfony2)

php - Doctrine Doctrine :schema:update command produces the same set of queries again and again

javascript - 包含最后一个数组元素的表单集合