note 88431 rejected from pdostatement.getcolumnmeta by danbrown
| From: | danbrown@php.net | Date: | Fri, 23 Jan 2009 18:17:11 +0000 |
| Subject: | note 88431 rejected from pdostatement.getcolumnmeta by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149711@lists.php.net to get a copy of this message | ||
Note Submitter: colin at fusionbox dot com
----
I haven't seen much discussion about this method, which is surprising since it is so useful
when building an ORM, which I'm doing.
Situation: Table Discussion (id, title) and Table Comment (id, title, discussion_id). A simple
has_many situation.
SELECT * FROM Discussion LEFT JOIN Comment ON Comment.discussion_id = Discussion.id\G
**** 1. row ****
id: 1
title: discussion_title
id: 1
title: comment_title_1
discussion_id: 1
**** 2. row ****
id: 1
title: discussion_title
id: 2
title: comment_title_2
discussion_id: 1
When building the objects, we'd like to end up with:
object Discussion
id: 1
title: discussion_title
comments: array(2)
[0] => object Comment
id: 1
title: comment_title_1
[1] => object Comment
id: 2
title: comment_title_2
To build this, though, we either need to give every column an alias (like "table.column")
and then parse the results using PDO::FETCH_ASSOC, OR get some meta-data about the columns and use
PDO::FETCH_NUM. getColumnMeta provides an elegant solution (and understands aliases, which is
great), but I need to know how well it's supported. MySQL 5.0+ seems to work great, but what
about PostgreSQL, Oracle, and MSSQL?