Re: getRow() API

From: Date: Sat, 19 May 2001 08:27:42 +0000
Subject: Re: getRow() API
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-397@lists.php.net to get a copy of this message
[Andrei Zmievski <andrei@ispi.net>] > I feel that the last two parameters to DB::getRow() should be reversed. > > Currently, it's: > > getRow($query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array()); > > You would most likely use getRow() with non-empty params much more often > than specifying a $fetchmode. Most people would probably just use > setFetchMode() to set the default mode and forget about it. I think we > should change it to: > > getRow($query, $params = array(), $fetchmode = DB_FETCHMODE_DEFAULT); Please test the attached patch and let me know if it does what you want (I did the same thing to getAll for consistency): - Stig Index: common.php =================================================================== RCS file: /repository/php4/pear/DB/common.php,v retrieving revision 1.48 diff -u -r1.48 common.php --- common.php 2001/04/24 11:47:01 1.48 +++ common.php 2001/05/19 08:23:35 @@ -460,9 +460,17 @@ * 0, or a DB error code. */ - function &getRow($query, $fetchmode = DB_FETCHMODE_DEFAULT, - $params = array()) + function &getRow($query, + $params = array(), + $fetchmode = DB_FETCHMODE_DEFAULT) { + // compat check, the params and fetchmode parameters used to + // have the opposite order + if (is_array($fetchmode) { + $tmp = $params; // this is our new fetchmode + $params = $fetchmode; + $fetchmode = $tmp; + } settype($params, "array"); if (sizeof($params) > 0) { $sth = $this->prepare($query); @@ -668,9 +676,17 @@ * @return array an nested array, or a DB error */ - function &getAll($query, $fetchmode = DB_FETCHMODE_DEFAULT, - $params = array()) + function &getAll($query, + $params = array(), + $fetchmode = DB_FETCHMODE_DEFAULT) { + // compat check, the params and fetchmode parameters used to + // have the opposite order + if (is_array($fetchmode) { + $tmp = $params; // this is our new fetchmode + $params = $fetchmode; + $fetchmode = $tmp; + } settype($params, "array"); if (sizeof($params) > 0) { $sth = $this->prepare($query);

« previous php.pear.dev (#397) next »