Simple database value object

This class sets, gets and deletes a single value stored in a database. The record doesn't need to have an index/ID. Upon creation of the object, the database (optional), table and column where the value is stored, are defined. Also the column name and it's value to select the value have to be defined.

category Database
package Formaid
author Dieter Adriaenssens
copyright 2006-2013 Dieter Adriaenssens
license GPL
link http://formaid.sourceforge.net/
todo create GeneralDbValue class that can get/store multiple values from the same record, or use multiple statements in the where clause
todo create class that handles data in a record with an ID (relational Db)

 Methods

Constructor, defines simple database value class

__construct(string $valueColumn, string $selectColumn, string $table, string $selectValue, string $database, bool $clearDbValue) : void

Defines current value and default value.

Parameters

$valueColumn

string

Column name of value

$selectColumn

string

Column to select on

$table

string

Table with value

$selectValue

string

Value to select on (optional, default : null)

$database

string

Database with value (optional, default : null)

$clearDbValue

bool

if true clear value instead of removing the record (optional, default : false)

Deletes a value stored in a database.

deleteDbValue(bool $clearDbValue) : bool

If $clearValue is true, the value in the database will be set to '', otherwise, the record will be removed.

Parameters

$clearDbValue

bool

if true clear value instead of removing the record

Returns

booltrue if deleting value was succesful

Disables trimming whitespace of object name

disableTrimName() : void
Inherited
inherited_from \Formaid_Object::disableTrimName()
inherited_from \Formaid_Property::disableTrimName()

Display object

display() : void
Inherited

The name of the object is printed to stdout.

inherited_from \Formaid_Object::display()
inherited_from \Formaid_Property::display()

Enables trimming whitespace of object name

enableTrimName() : void
Inherited
inherited_from \Formaid_Object::enableTrimName()
inherited_from \Formaid_Property::enableTrimName()

Gets a value stored in a database.

getDbValue() : mixed

Returns

mixedvalue from database

Get display seperator

getDisplaySeparator() : string
Inherited
inherited_from \Formaid_Property::getDisplaySeparator()

Returns

stringString separating columns

return Display string

getDisplayString(bool $withValue, bool $discardEmptyValue) : string
Inherited
access public
inherited_from \Formaid_Property::getDisplayString()

Parameters

$withValue

bool

append value to column (optional, default : true)

$discardEmptyValue

bool

discard columns with empty values (optional, default : false)

Returns

stringformatted object string

Returns name of the object

getName() : string
Inherited
inherited_from \Formaid_Object::getName()
inherited_from \Formaid_Property::getName()

Returns

stringobject name

Returns current value

getValue() : string
Inherited
inherited_from \Formaid_Property::getValue()

Returns

stringcurrent value

Checks if current value is empty

isEmpty() : bool
Inherited
inherited_from \Formaid_Property::isEmpty()

Returns

booltrue if empty

Checks if object name is empty

isNameEmpty() : bool
Inherited
inherited_from \Formaid_Object::isNameEmpty()
inherited_from \Formaid_Property::isNameEmpty()

Returns

booltrue if empty

Resets current value

resetValue() : void
Inherited

Empty current value

inherited_from \Formaid_Property::resetValue()

Stores a value in a database.

setDbValue(mixed $value) : bool

If the value does not exist in the database, add it. If the new value is the same as the one in the database, do nothing. If a value already exists in the database, update the value.

Parameters

$value

mixed

New value

Returns

booltrue if setting value was succesful

Sets current value to default

setDefault(string $value) : void
Inherited

When the parameter is set, the default value is changed to the new default value. Then the current value is set to the (new) default value.

inherited_from \Formaid_Property::setDefault()

Parameters

$value

string

New default value

Sets new name for the object

setName(string $new_name) : void
Inherited
inherited_from \Formaid_Object::setName()
inherited_from \Formaid_Property::setName()

Parameters

$new_name

string

new name

Sets current value to new value

setValue(string $new_value) : void
Inherited
inherited_from \Formaid_Property::setValue()

Parameters

$new_value

string

New value

Show object

show() : void
Inherited

The name of the object is printed to stdout.

inherited_from \Formaid_Object::show()
inherited_from \Formaid_Property::show()

Returns name formatted for displaying

getDisplayName() : string
Inherited
inherited_from \Formaid_Object::getDisplayName()
inherited_from \Formaid_Property::getDisplayName()

Returns

stringformatted object name

Returns value formatted for displaying

getDisplayValue() : string
Inherited
access protected
inherited_from \Formaid_Property::getDisplayValue()

Returns

stringformatted object value

Creates WHERE clause

getWhereClause() : string

WHERE clause selecting for selectColumn = selectValue

Returns

stringWHERE clause

Deletes a value stored in a database using a DELETE statement.

_deleteDbValue() : \handle

Returns

\handlequery result

Inserts a value in a database using an INSERT statement.

_insertDbValue(mixed $value) : \handle

Parameters

$value

mixed

New value

Returns

\handlequery result

Gets a value from a database using a SELECT statement.

_selectDbValue() : string

Returns

stringvalue from database

Updates a value in a database using an UPDATE statement.

_updateDbValue(mixed $value) : \handle

Parameters

$value

mixed

New value

Returns

\handlequery result

 Properties

 

$clearDbValue : object
access public
 

$selectValue : object
access public
 

$current_value : string
Inherited
access protected
inherited_from \Formaid_Property::$$current_value
 

$default_value : string
Inherited
access protected
inherited_from \Formaid_Property::$$default_value
 

$displaySeparator : string
Inherited
access protected
inherited_from \Formaid_Property::$$displaySeparator
 

$encoding : string
Inherited
access protected
inherited_from \Formaid_Object::$$encoding
inherited_from \Formaid_Property::$$encoding
 

$name : string
Inherited
access protected
inherited_from \Formaid_Object::$$name
inherited_from \Formaid_Property::$$name
 

$selectColumn : object
access protected
 

$table : object
access protected
 

$valueColumn : object
access protected
 

$_dbConn 
access private
type object
 

$_trimName : bool
Inherited
access private
inherited_from \Formaid_Object::$$_trimName
inherited_from \Formaid_Property::$$_trimName