From:             
Operating system: *
PHP version:      5.3.2
Package:          PDO related
Bug Type:         Feature/Change Request
Bug description:PDO::FETCH_FUNC should also work with fetch()

Description:
------------
Currently, PDO::FETCH_FUNC can only be used in the PDOStatement::fetchAll()
method. This fetch mode, however, is essentially useless since it can not
be set using setFetchMode() or fetch(), and thus can not be used in
iteration. 

Test script:
---------------
<?php

$db = new PDO(...);

$stmt = $db->execute("SELECT * FROM foobar");

$stmt->setFetchMode(PDO::FETCH_FUNC, 'var_dump');

foreach($stmt as $row):

    ...

endforeach;

?>

Expected result:
----------------
PDO should set the fetch mode to FETCH_FUNC, and should call var_dump()
when $stmt is iterated. Because no additional fetch modes were passed to
setFetchMode(), var_dump() should receive an argument representing the row
in PDO::FETCH_BOTH format. $row should be set to the return of var_dump(),
and control should now be passed to the foreach codeblock.



IMHO, FETCH_FUNC should allow one to provide a callback function that
allows full manipulation of the row before being passed into the iteration
codeblock. For example, in an active record implementation, one would have
to set the FETCH_CLASS method and suffer a very costly object
instantiation. A callback function would allow me to clone an existing (and
fully loaded) object, set my properties, and return it -- saving me upwards
of 90% in execution costs for heavy objects.

Actual result:
--------------
Warning: PDOStatement::setFetchMode() [pdostatement.setfetchmode]:
SQLSTATE[HY000]: General error: PDO::FETCH_FUNC is only allowed in
PDOStatement::fetchAll()

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51308&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51308&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51308&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51308&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51308&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51308&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51308&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51308&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51308&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51308&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51308&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51308&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51308&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51308&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51308&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51308&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51308&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51308&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51308&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51308&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51308&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51308&r=mysqlcfg

Reply via email to