Aliro Documentation : aliroDatabaseRow

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Revision [1252]

Most recent edit made on 2011-11-09 18:32:52 by MartinBrampton

Additions:
bool = load ( [$key=null] )
bool = delete ( [$key=null] )


Deletions:
bool = load ([$key=null])
bool = delete ([$key=null])




Revision [1251]

Edited on 2011-11-09 18:32:21 by MartinBrampton

Additions:
bool = load ([$key=null])
bool = store ( $updateNulls=false )
bool = bind ( $objectorarray, $ignore=, $strip=true )
bool = delete ([$key=null])
int = getAffectedRows ()


Deletions:
bool = load([$key=null])
bool = store( $updateNulls=false )
bool = bind( $objectorarray, $ignore=, $strip=true )
bool = delete([$key=null])
int = getAffectedRows()




Revision [1250]

Edited on 2011-11-09 18:31:04 by MartinBrampton

Additions:
The property DBclass is the name of the database class, the optional property DBReadClass is the name of the read only database class, the property tableName is the name of the database table, and the property rowKey is the name of the field that is the primary key. The code could be extended to handle multi-column keys, but at present it is best to assume that only single column primary key tables are supported. Methods such as "store" assume that the table has a primary key with auto increment.
When this method is used, the database row object may already have its primary key property set with the value that defines the row. Or the key can be passed as a parameter. If a database row can be read using the provided key, then the object will acquire the values of the row in the database and the return value will be true. If no such row can be found, the return value will be false and the database row object is unchanged.
bool = store( $updateNulls=false )
Whether this method attempts to insert a row or update a row depends on whether the primary key property of the object has a non-empty value. If a non-empty value is present, and update will be attempted; otherwise an insert. An update can fail because the primary key property does not match a row in the database, in which case the return value is false. If the primary key property is not set, then the object values will be inserted into the table as a new row, and the primary key property will be set with the value of the new key (assuming an auto increment table). The "updateNulls" parameter is a boolean and is relevant only to updates. If set to true, then null values in the object will be written to the database fields; if it is false, they will be ignored.
bool = bind( $objectorarray, $ignore=, $strip=true )
This method will set the properties of the object to values from matching fields in the given object or array. If the first parameter is not either an object or an array, the return value will be false, otherwise true. The "ignore" parameter can specify a comma separated list of fields to be ignored in the object or array. The "strip" parameter is a boolean saying whether to strip any magic quotes from the values in the object or array. The method is commonly used with $_POST as the first parameter, but can be used with any object or array.
bool = delete([$key=null])
A row in the table can be deleted with this method. Typically the key is taken from the primary key property of the object, but it can be passed as a parameter. The return value will always be true (for backwards compatibility) and to find out whether a deletion actually took place, the number of rows affected should be queried - see below
int = getAffectedRows()
Returns the number of affected rows from the previous operation.


Deletions:
The property DBclass is the name of the database class, the optional property DBReadClass is the name of the read only database class, the property tableName is the name of the database table, and the property rowKey is the name of the field that is the primary key. The code could be extended to handle multi-column keys, but at present it is best to assume that only single column primary key tables are supported.
Returns the error number for the most recent SQL operation. Note that most errors will cause a database exception, so applications must trap this exception if they will to do their own error processing.




Revision [1249]

Edited on 2011-11-09 18:16:02 by MartinBrampton

Additions:
bool = load([$key=null])
Returns the error number for the most recent SQL operation. Note that most errors will cause a database exception, so applications must trap this exception if they will to do their own error processing.




Revision [1248]

Edited on 2011-11-09 18:13:57 by MartinBrampton

Additions:
Note that there is no need to write code to describe the fields that exist in the database table. This information will be automatically extracted from the database. There are also methods available on aliroExtendedDatabase to manipulate the database, allowing information to be obtained and tables updated. For example, there is a method to add a field if it does not currently exist.
The key methods are the following:




Revision [1247]

The oldest known version of this page was edited on 2011-11-09 18:09:00 by MartinBrampton

aliroDatabaseRow


This abstract class is subclassed to create classes that correspond to database rows. The subclass should define some standard properties. A typical example is:

class subscriptionType extends aliroDatabaseRow {
	protected $DBclass = 'gpsDatabase';
	protected $DBReadClass = 'gpsReadDatabase';
	protected $tableName = 'user_subscription';
	protected $rowKey = 'id';
	
}


The property DBclass is the name of the database class, the optional property DBReadClass is the name of the read only database class, the property tableName is the name of the database table, and the property rowKey is the name of the field that is the primary key. The code could be extended to handle multi-column keys, but at present it is best to assume that only single column primary key tables are supported.

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.1217 seconds