ID: 42664 User updated by: jdriddle_producer at yahoo dot como Reported By: jdriddle_producer at yahoo dot como Status: Open Bug Type: Feature/Change Request Operating System: all PHP Version: 5.2.4 New Comment:
After additional thought, it might be better to add this functionality to PDOStatement->fetchObject() instead. That way there would be no chance of mucking up PDOStatement-> fetch() with the added parameters. Previous Comments: ------------------------------------------------------------------------ [2007-09-13 18:37:49] jdriddle_producer at yahoo dot como 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42664&edit=1