Re: [PATCH] PDO::setDefaultFetchMode() methode

From: Date: Wed, 19 Oct 2005 14:01:46 +0000
Subject: Re: [PATCH] PDO::setDefaultFetchMode() methode
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3124@lists.php.net to get a copy of this message
Ilia Alshanetsky wrote:
I don't see this patch as necessary you can already specify the fetch mode in many different places. Enough it enough so to speak.
But you allways must set the FetchMode for EVERY query! If you can set a default FetchMode in PDO class, you can set the fetchMode at one time for your whole application. I see much more use for a PDO::setDefaultFetchMode() than for PDOStatement::setFetchMode(), because you have to call the latter for every query / statement! There are many users of PDO who wonder, why this is not possible today. What's the disadvantage of a PDO::setDefaultFetchMode() methode? It's not very much code (and I'll try to finish it), you don't slow down anything, it is only called once by useres who want to use it... and it is a feature which many users would like to see (not only from the two feature requests in the bug-trackers or some threads on php.pecl.dev/php.pear.dev) and which is on the same abstraction level like the whole API. An example: <?php $stmt1 = $pdo->query($sql1, PDO::FETCH_OBJ); $stmt2 = $pdo->query($sql2, PDO::FETCH_OBJ); $stmt3 = $pdo->query($sql3, PDO::FETCH_OBJ); $stmt4 = $pdo->query($sql4, PDO::FETCH_OBJ); $stmt5 = $pdo->query($sql5, PDO::FETCH_OBJ); [...] ?> why not: <?php // set only once for the whole application $db->setDefaultFetchMode(PDO::FETCH_OB); $stmt1 = $db->query($sql1); $stmt2 = $db->query($sql2); $stmt3 = $db->query($sql3); $stmt4 = $db->query($sql4); $stmt5 = $db->query($sql5); [...] ?> So you can hide the PDO constants and write much nicer/simpler code, if you're not happy with PDO::FETCH_BOTH. And you often have more complex scripts with more than 20, 30 or even more queries in it. Only if you are willing to use PDO::FETCH_BOTH you can write the simple code like the second example today, which could easily be changed (as shown in the patch), so all users could benfit from it. Also people using arrays for result-sets - which works with PDO::FETCH_BOTH - will probably be even more happy when PDO::FETCH_ASSOC could be used in the same simple/intuitive way, to avoid that PDO writes all the data into the arrays twice. best regards Andreas

« previous php.pecl.dev (#3124) next »