Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-20-2005, 10:56 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
Arrow new mysql_fetch_object() article

Hey all, I wrote a new article on mysql_fetch_object().

http://php.codenewbie.com/articles/p...ct-Page_1.html

Let me know what you think.
__________________
Mike
sde is offline   Reply With Quote
Old 01-22-2005, 09:12 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Cool stuff. Looks similar to some of the db object structure I use in an old framework. Basically each table has a class that inserts and retrieves data. From there I define the fields I want to retrieve in an array (which isn't necessary, but I don't always like to fetch every field for every call)

A basic class would be like:

PHP Code:
class foo extends fooModule {
  var 
$assign_vars = array(
      
'foo_id''foo_name''foo_this',
   );

   class 
foo($id=0) {
      
$par get_parent_class($this);
      
$this->$par();

      if (
$id) {
         
$this->_get($id);
      }

   }

   class 
_foo() {
      
// destruction
      
return;
   }

// other public methods go here
//

   // {{{ _get()
   
function _get($id)
   {
      
$db newObject('fooModule::Db');
      
$q  = <<<EOQ
         SELECT *
         FROM 
{$this->t['TBL_FOO']}
         WHERE foo_id = '
{$id}'
EOQ;

      
$db->query($q);
      
$db->next_record();
      
$this->_assign($db->Record);
   }
   
// }}}


So then I can grab an object pretty quickly and/or create other functions that search and return an array of objects.

PHP Code:

$obj 
newObject('Module::foo'$id);

or
$results $obj->getActiveFoo();

foreach (
$results as $k => $v) {
   echo 
$v->foo_id;
   
//etc.


I'm still looking for a new framework to use and pear's DB and DB_DataObject look pretty cool. (especially dataobject - you just describe the data and tell it what kinds of things you want to do in you code.. no manual SQL flipping)

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Template Specialization Article sde Standard C, C++ 1 12-29-2004 12:56 AM
Code Newbie Article Contest Update sde Lounge 0 11-29-2004 08:31 AM
Code Newbie Article Writting Contest ( coming very soon ) sde Lounge 1 11-09-2004 07:59 AM
BUG: Opening an 'open' article DavH27 Feedback 3 10-31-2004 07:25 AM
What a new article looks like with images .. sde Lounge 0 10-27-2004 05:37 PM


All times are GMT -8. The time now is 12:45 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting