note 88431 added to pdostatement.getcolumnmeta

From: Date: Fri, 23 Jan 2009 18:15:47 +0000
Subject: note 88431 added to pdostatement.getcolumnmeta
Groups: php.notes 
Request: Send a blank email to php-notes+get-149710@lists.php.net to get a copy of this message
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? ---- Server IP: 64.71.164.2 Probable Submitter: 67.176.31.220 ---- Manual Page -- http://www.php.net/manual/en/pdostatement.getcolumnmeta.php Edit -- https://master.php.net/note/edit/88431 Del: integrated -- https://master.php.net/note/delete/88431/integrated Del: useless -- https://master.php.net/note/delete/88431/useless Del: bad code -- https://master.php.net/note/delete/88431/bad+code Del: spam -- https://master.php.net/note/delete/88431/spam Del: non-english -- https://master.php.net/note/delete/88431/non-english Del: in docs -- https://master.php.net/note/delete/88431/in+docs Del: other reasons-- https://master.php.net/note/delete/88431 Reject -- https://master.php.net/note/reject/88431 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149710) next »