Re: [PHP-DB] Fwd: About PDO::fetchObject

[email protected] (Aziz Saleh) Thu, 11 Jun 2015 09:41:54 -0400
Newsgroups php.db
Message-ID <CAPJtNhXsVjU-Mpbrw5pkZmN8x_uafmPA8ffTc4bOG1nu6Qv6Dw@mail.gmail.com>
On Thu, Jun 11, 2015 at 1:53 AM, Octopus Puras <[email protected]> wrote:

> I have a MySQL table, whose name is Items:
> ItemID ItemName ItemDescription
>
> I also have a PHP class:
> class Item {
>   public $id;
>   public $name;
>   public $description;
> }
>
> If I execute $stmt->fetchObject(), I will get an object with fields of
> ItemID, ItemName, etc. But I want to adapt the name of the fields to the
> Item class. What should I do?
>

It would be easier/more efficient/easier to debug to change the field names
to what you want to, instead of having to do that manually like Stefan
suggested.