PHP Classes

MySQL Table Abstraction Class: Wrap the access to MySQL database table rows

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 801 All time: 4,281 This week: 206Up
Version License Categories
mtac 1.0GNU General Publi...PHP 5, Databases
Description 

Author

This class can be used to wrap the access to individual MySQL database table rows in class objects.

Each object of the class stores the values of the fields of a given row of a given table.

The class provides means to store and retrieve the values of the row fields in the specified table.

It can retrieve the row values given the value of a field named 'id' or named 'name'. The field values are stored in class variable that is an associative array.

Then the class can also store the eventually modified table fields values. If the id field value is set to 0, the class inserts a new table record.

Picture of Nic Stevens
Name: Nic Stevens <contact>
Classes: 2 packages by
Country: United States United States
Age: 58
All time rank: 58877 in United States United States
Week rank: 164 Up23 in United States United States Up

Details

MySQL Table Abstraction Class (MTAC) MTAC is a small class that provides consistent methods and encapsulates data for MySQL tables. Essentially MTAC defines an associative array from a database row without having to worry about fetching the data. For a data to be encapsulated it needs, at a bare minimum, two common table columns, name and id. Suppose, for example, that we have a table containing information about a user. We can instantiate the user data with the following snippet: $user = new mtac($db,"user","Frank Jones"); This will create a user object with the following properties: class mtac { var $table; var $db; var $d; } $table is the stored table name passed on instantiation. $db is the handle to a MySQL connection. $d is an associative array of the data returned by the MySQL server. Other than Id and Name the table can have any number of columns and those data are stored in the associative array $mtac->d. If I add more tables -- the code still works. The only stipulation is that each table must have two properties in common: Name and Id. The code figures out which table and column to select in the database based on the two parameters passed on initialization (table,id). This is a simple means for retriving data without worrying about the details of the transaction with the MySQL server. This software is Copyright (C) 2005 Nic Stevens, Seattle, WA, US. This software is licensed for use under the Gnu Public License (Please see the enclosed gpl.txt)

  Files folder image Files (4)  
File Role Description
Plain text file mtac.php Class MySQL Table Abstraction Class
Accessible without login Plain text file README Doc. Details on MTAC
Accessible without login Plain text file test.php Example MTAC Test
Accessible without login Plain text file test.sql Data Test database tested against

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:801
This week:0
All time:4,281
This week:206Up