|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-13 19:29 UTC] jdriddle_producer at yahoo dot como
[2011-02-21 21:01 UTC] jani@php.net
-Package: Feature/Change Request
+Package: PDO related
-Operating System: all
+Operating System: *
[2011-09-12 21:09 UTC] restlesslythought at gmail dot com
[2021-09-29 16:02 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-09-29 16:02 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 14:00:01 2025 UTC |
Description: ------------ Currently, the PDO::FETCH_CLASSTYPE option is used with PDO::FETCH_CLASS in $result->fetch() in order to create an object based upon a classname determined by data in the table. Unfortunately, the method looks for the FIRST COLUMN in the result. This is counter to common relational database design. The only way to currently work around this and get at the desired functionality is to abandon the common 'SELECT * from $tableName' construct that is so useful in abstraction, and use custom 'SELECT classType, col2,col3,... from _tableName_' for each query. I suggest that the PDO::FETCH_CLASSTYPE option be changed to take an optional parameter, $colName, for the column name to look for the class name in. The current behavior would remain as the default. This would allow: $objArray = []; $query = "SELECT * from $tableName"; $result = $dbh->query($query); $count = $result->rowCount(); for($i=0;$i<$count;$i+=1) { $objArray[] = $result->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE,"classType"); } Or similar construct.