|
Posted by Matthew Weier O'Phinney on 09/30/53 11:22
* Jochem Maas <jochem@iamjochem.com> :
> Matthew Weier O'Phinney wrote:
> > * Patrick Roane <fojomo@sbcglobal.net> :
> > > I'm on ch 7 of the php5/myswl/ecomm book.
> > >
> > > There is an error I get whenever I press the 'Edit
> > > Categories' button:
> > >
> > > Fatal error: Cannot use object of type DB_result as array in
> > > c:\customfurniture\templates_c\%%F9^F97^F97AE06E%%admin_categories.tpl.php
> > > on line 49
> >
> > Sounds to me like you're either (1) trying to access an object using
> > array-style syntax in Smarty, or (2) you're passing the wrong item to
> > the template.
>
> Now I happen to know that you (Matthew Weier O'Phinney) are a 'heavy'
> user of some/one of the PEAR DB classes because I read the php
> generals list alot... I'm guessing your comments below are aimed at
> functionality found in PEAR (which DB related class I have no idea)
> but it's only implied - might I suggest that, given the fact Patrick
> calls himself a 'newbie', that you make it a little more explicit so
> that he knows what you mean when you start talking about stuff like
> DB_FETCHMODE_OBJECT. it would be ashame if your insight was lost on
> him because he didn't grok the 'context'.
Good point. I'd made the assumption that the book the OP is using would
have these details, but this may very well not be the case. I've put
some clarifications below.
> > In the case of (1), you probably retrieved the results of a DB call as
> > an object (perhaps by setting DB_FETCHMODE_OBJECT), and passed the
> > object to the template.
From the error returned, I inferred the OP was using PEAR::DB --
DB_result objects are returned from queries made with PEAR::DB. When
fetching results from PEAR::DB, one may choose the format in which the
results are returned. The default is as an array (DB_FETCHMODE_ARRAY),
but one can choose an associative array of fieldname => value pairs
(DB_FETCMODE_ASSOC) or an object with each fieldname being a property of
the object (DB_FETCHMODE_OBJECT). Since I don't know the book in
question, nor has the OP posted code, I'm not sure what kind of
resultset was requested.
Of course, my deduction that the OP is using PEAR::DB may be completely
wrong, in which case the above may be safely ignored ;-)
Regardless, the following stuff may still be relevant based on how the
resultset is returned (as associative array vs object):
> > Then you used syntax like:
> >
> > {$result.name}
> >
> > to print out the 'name' field of the result. However, that syntax is for
> > accessing elements in an array; the correct syntax would be:
> >
> > {$result->name}
> >
> > which would access the name property of the object.
> >
The following is making the assumption that PEAR::DB is being used;
again, ignore if this is not the case. Additionally, if the OP is indeed
using PEAR::DB s/he may want to consult the PEAR::DB manual, located at:
http://pear.php.net/manual/en/package.database.db.php
> > In the case of (2), you may have performed a query that returned a
> > resultset, but you didn't pull a record or set of records from the
> > resultset to pass to the template. For example:
> >
> > $results = $db->query($sql);
> > $tpl->assign('result', $results);
> >
> > when you should have done something like:
> >
> > $results = $db->query($sql);
> > $row = $results->fetchRow(DB_FETCHMODE_ASSOC);
> > $tpl->assign('result', $row);
Cheers!
--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/
Navigation:
[Reply to this message]
|