note 88432 added to pdostatement.getcolumnmeta

From: Date: Fri, 23 Jan 2009 18:38:44 +0000
Subject: note 88432 added to pdostatement.getcolumnmeta
Groups: php.notes 
Request: Send a blank email to php-notes+get-149712@lists.php.net to get a copy of this message
This method is supported in the MySQL 5.0+ driver. It can be used for object hydration: <?php $pdo_stmt = $dbh->execute('SELECT discussion.id, discussion.text, comment.id, comment.text FROM discussions LEFT JOIN comments ON comment.discussion_id = discussion.id'); foreach(range(0, $pdo_stmt->columnCount() - 1) as $column_index) { $meta[] = $pdo_stmt->getColumnMeta($column_index); } while($row = $pdo_stmt->fetch(PDO::FETCH_NUM)) { foreach($row as $column_index => $column_value) { //do something with the data, using the ids to establish the discussion.has_many(comments) relationship. } } ?> If you are building an ORM, this method is very useful to support more natural SQL syntax. Most ORMs require the column names to be aliases so that they can be parsed and turned into objects that properly represent has_one, has_many, many_to_many relationships. ---- 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/88432 Del: integrated -- https://master.php.net/note/delete/88432/integrated Del: useless -- https://master.php.net/note/delete/88432/useless Del: bad code -- https://master.php.net/note/delete/88432/bad+code Del: spam -- https://master.php.net/note/delete/88432/spam Del: non-english -- https://master.php.net/note/delete/88432/non-english Del: in docs -- https://master.php.net/note/delete/88432/in+docs Del: other reasons-- https://master.php.net/note/delete/88432 Reject -- https://master.php.net/note/reject/88432 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149712) next »