开发者

Symfony2 Doctrine

开发者 https://www.devze.com 2023-03-19 11:10 出处:网络
I try to do a database query using $position = $repository->findBy( array(\'id\' => $profileId,\'datum\' => \'10.07.2011\'),

I try to do a database query using

$position = $repository->findBy(
    array('id' => $profileId,'datum' => '10.07.2011'),
    array('timestamp', 'DESC'开发者_StackOverflow社区)
);

the database looks like

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

The result I get is always the data of the last day into the database. In this case '12.07.2011'.


Using varchar for dates is probably the worst approach possible. Change the datum field to date or datetime, change your models accordingly so the doctine field is date and then do something like:

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

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

Brief on schema practises which i would advice to review: http://brixican.blogspot.ca/2011/04/5-mysql-best-practices-when-designing.html


If database field for 'datum' is datetime, try to use: 2011-07-10 format :-)
Symfony2 articles


I agree with others that you should change the field to Datetime format, however if you are using Symfony2 in the developer mode you can check SQL logs (DB Queries) that correspond to your Doctrine ORM query builder and from there you may know what's wrong with your query builder

0

精彩评论

暂无评论...
验证码 换一张
取 消