Can I get an opinion on this class, and the features it offers?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    #1

    Can I get an opinion on this class, and the features it offers?

    Well, I came up with an idea a couple of days ago. Though I'm not sure how well it'll do in the long run, but for now, I like the idea, as it'll help me clean up my projects code a bit once I implement it.

    But I want a 2nd opinion from any Expert who is willing to look it over real quick.

    Summary:
    • Data class;
    • Caches database entries of a given table (more then one class type) via json_encode();
    • Each "Column" of database has class property;
    • method set_id() sets each property, mentioned above, to the supplied database entry id;
    • has cycle feature, auto cycles through each database entry, effectively making it a loop;


    Heres my basic usage assuming theres DB Entries:
    Code:
    // Two different database tables, with similar Columns / Properties
    $equipment = new Type('equipment');
    $repair = new Type('repair');
    
    // Single Entry usage
    $equipment->set_id(4);
    echo 'ID: ', $equipment->id, '; Name: ', $equipment->name, ';';
    
    // Cycle through all entries
    $repair->cycle_start();
    for ($i=0;$i<$repair->count;$i++) {
        echo 'ID: ', $repair->id, '; Name: ', $repair->name, ';<br>';
        $repair->cycle_next();
        }
    $repair->cycle_end();
    Mostly I like it cause I won't have to deal with indexes, and all the dang brackets. lol...

    So I would like an opinion if anyone wishes to share please. Thanks.
    Attached Files
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what you describe sounds like an ORM (object relational mapper, Doctrine or PHP.AR for instance).

    if you don’t need a full database abstraction, you can use PDO for accessing the database data. that will give you effective database access at least (fetching & looping through data is a piece of cake)

    IMHO, there is no gain in caching full DB results (some queries may result in huge result sets which would eat your memory away and DB access doesn’t take long)


    PS. if you make a DB class, don’t use outdated functions for it.
    Last edited by Dormilich; Jan 23 '11, 08:54 AM.

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      PS. if you make a DB class, don’t use outdated functions for it.
      Would you consider MySQLi out dated?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        no. though I’d recommend PDO.

        Comment

        Working...