From:             jdriddle_producer at yahoo dot como
Operating system: all
PHP version:      5.2.4
PHP Bug Type:     Feature/Change Request
Bug description:  PDO::FETCH_CLASSTYPE is not useful for abstracting code.

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 bug report at http://bugs.php.net/?id=42664&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42664&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42664&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42664&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42664&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42664&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42664&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42664&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42664&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42664&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42664&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42664&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42664&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42664&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42664&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42664&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42664&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42664&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42664&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42664&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42664&r=mysqlcfg

Reply via email to