0

I have a DB table Entity and a corresponding DTO class Entity (no constructor arguments).

When I do this:

$entity=$connection->query("Select * FROM Entity WHERE id='1'",
    PDO::FETCH_CLASS,
    'Entity',
    NULL);

Then $entity is a PDOStatement containing one object of class Entity.

How can I retrieve this one Entity object without looping over $entity with a foreach?

PDOStatment:fetchObject didn't seem like a good solution, because it's going to map the Entity object in the PDOStatement on a new Entity object.

4

1 回答 1

0

我相信你能做到

$entity = $connection->query("Select * FROM Entity WHERE id='1'",
    PDO::FETCH_CLASS,
    'Entity',
    NULL)->fetch(PDO::FETCH_CLASS);

我以前从未尝试过使用这样的查询方法,所以这可能行不通。

于 2013-08-31T21:53:04.103 回答