Re: DB::getAssoc doesn't use global fetchmode
| From: | Alex Howansky | Date: | Thu, 05 Sep 2002 21:03:36 +0000 |
| Subject: | Re: DB::getAssoc doesn't use global fetchmode | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-8860@lists.php.net to get a copy of this message | ||
> > should yeild the same result as in the second example where DB_FETCHMODE_ASSOC
> > was passed explicitly, but it doesn't -- it gives the same result as the first
> > example, as if you had specified DB_FETCHMODE_ORDERED. Is that correct?
>
> Yes, it is in fact correct. If you don't pass a value for the 4th
> parameter to the method, it will take DB_FETCHMODE_ORDERED as the
> default value, which leads to the result you've experienced.
Yes, I noticed that -- the code is certainly working as written. I suppose I
could have worded my question better. I guess what I meant to ask was, is it
working as intended? Seems not, since both getRow and getAll use the value set
by setFetchMode. I don't see the logic in having getAssoc ignore it, so I'm
guessing it's just an oversight.
> A solution to this problem might be to use DB_FETCHMODE_DEFAULT as the
> default value for the parameter. In this case the fetchmode that has
> been defined via setFetchMode() will be used.
I tried that, it didn't work. The method explicitly compares the constants:
if ($fetchmode == DB_FETCHMODE_ASSOC) {
...
} else {
...
}
Since DB_FETCHMODE_ASSOC != DB_FETCHMODE_DEFAULT, the "else" happens, which is
hardcoded to DB_FETCHMODE_ORDERED.
I got it to work by adding this statement:
if (empty($fetchmode)) { $fetchmode = $this->fetchmode; }
to the start of the getAssoc method.
> But actually I'm a bit
> afraid that this will break a number of existing scripts.
Bah! Backward compatibility is for wimps!
--
Alex Howansky
Wankwood Associates
http://www.wankwood.com/