|
|
Home Manual 11. API Reference [WORKING] mosDBTable class |
| [WORKING] mosDBTable class |
|
|
|
|
Last reviewed: Not reviewed Abstract database table class. This is the parent class to all database derived objects. Customisation will generally not involve tampering with this class. Each table of the Joomla database has a class of type mosDBTable associated with it. The parent class defines a set of default functions that will suffice for the majority of tables, but which may be overridden if required. If you are creating a component which requires its own table then you
are strongly advised to use the mosDBTable class so as to take advantage
of this default functionality. For example, suppose you have a table called myTable, containing just three fields: $id, $title and $published. Then you could define a class called, perhaps, myTable, as follows: /** * myTable database table class * @package MyComponent */ class myTable extends mosDBTable { /** @var int Primary key */ var $id=null; /** @var string */ var $title=null; /** @var boolean */ var $published=null; /** * @param database A database connector object */ function myTable( &$db ) { $this->mosDBTable( '#__myTable', 'id', $db ); } } Notice that you MUST define exactly the same attributes in the class as
the fields in the table schema definition. It is a common programming
error to add a new field to the table schema and forget to add the same
field as an attribute in the class definition. A symptom typical of this is when changes made to a database variable in program code are never saved to the physical database record. Also make sure that you set each variable to null otherwise problems can arise in some versions of PHP 4.1.x. You could then declare an instance of this table as follows: $myTbl = new myTable( $database ); Having declared an instance of the table the default functions allow for most requirements. For example, updating a row can be done like this: // Declare an instance of the myTable class. $myTbl = new myTable( $database ); // Load record with primary key id=17. $uid = 17; $myTbl->load( $uid ); // Update some fields in the table row. $myTbl->set( 'title', 'The title' ); $myTbl->set( 'published', true ); // Save the updated record. $myTbl->store(); More commonly the load will take place in one call to Joomla, where a form is constructed which the user fills in with the updated fields. The user then submits the form which calls a different routine in the component which will bind the $_POST array to the table object and then store the object in the database table. Joomla versionUnknown Defined inlibraries/joomla/database/mysql.php Functions
Please report any errors on this page to the Developer Documentation Forum. |
|
| Last Updated ( Sunday, 24 December 2006 ) |
| < Prev | Next > |
|---|





