Class myMVC_BaseDB

Description

Base class for a database table's class Every table must have a derived class with the check function Example:

  1.  class testDB extends myMVC_BaseDB
  2.  {
  3.    public function __construct()
  4.    {
  5.      parent::__construct('test',
  6.                          array('id'                  => 'testDB::checkId',
  7.                                'firstname'           => 'testDB::checkName',
  8.                                'lastname'            => 'testDB::checkName',
  9.                          ),
  10.                          array('id' => 'autoincrement'),
  11.                         // Unique Key: firstname+lastname
  12.                          array(array('firstname''lastname')));
  13.    }
  14.  
  15.    public static checkId($type$value)
  16.    {
  17.      return true;
  18.    }
  19.  ...
  20.  }

Located in /myMVC/BaseDB.php (line 51)

myMVC_TypeCheck
   |
   --myMVC_DatabaseConnector
      |
      --myMVC_BaseDB
Direct descendents
Class Description
Abstract class myMVC_BaseLogin Generic class for a user, that can log into the system.
 class myMVC_GenericSQL Generic class to query the database
 class myMVC_SessionDB Class to manage database-based sessions.
Variable Summary
 mixed $counters
 mixed $engine
 mixed $fields
 mixed $finders
 mixed $oldValues
 mixed $pk
 mixed $table
 mixed $uniques
 mixed $values
Method Summary
 static int callCounter (string $name, array $fields)
 static array callFinder (string $name, array $fields, [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
 static resource callIterator (string $name, array $fields, [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
 static void deleteAll (array $param)
 static array findAll ([string $order = NULL], [int $limit = NULL], [int $offset = NULL])
 static DB-Class findByPK (array $pk)
 static int getCountAll ()
 static resource iterateAll ([string $order = NULL], [int $limit = NULL], [int $offset = NULL])
 myMVC_BaseDB __construct (string $table, array $fields, array $pk, [array $uniques = NULL])
 void checkFields (array $param, string $type)
 void checkUniques ()
 string createWhere (array $param, [array $useLike = array()])
 void delete ()
 resource findByParameter (array $param, [array $useLike = array()], [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
 resource findBySQLQuery (string $sql)
 int getCountByParameter (array $param, [array $useLike = array()])
 bool isRecordUnique ()
 string now ()
 string nowFormatted ()
 void registerCounter (string $name, array $fieldsToSearch, [array $fixedFields = array()])
 void registerFinder (string $name, array $fieldsToSearch, [array $fixedFields = array()])
 void save ()
 void saveValues (array $values)
 string sqlExportByParameter (array $param, [array $useLike = array()], [string $order = NULL], [int $limit = NULL], [int $offset = NULL], [boolean $exportToBrowser = true], [int $separateAfter = 50])
 void __call ($name $name, $args $args)
Variables
mixed $autoincrement (line 57)
  • access: protected
mixed $counters (line 61)
  • access: protected
mixed $engine (line 59)
  • access: protected

Redefinition of:
myMVC_DatabaseConnector::$engine
mixed $fields (line 55)
  • access: protected
mixed $finders (line 60)
  • access: protected
mixed $oldValues (line 58)
  • access: protected
mixed $pk (line 54)
  • access: protected
mixed $table (line 53)
  • access: protected
mixed $uniques (line 56)
  • access: protected
mixed $values (line 58)
  • access: protected

Inherited Variables

Inherited from myMVC_DatabaseConnector

myMVC_DatabaseConnector::$database
myMVC_DatabaseConnector::$login
myMVC_DatabaseConnector::$password
myMVC_DatabaseConnector::$server
Methods
static callCounter (line 365)

Calls a defined counter (see registerCounter)

  • return: The count of the searched records
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
int callCounter (string $name, array $fields)
  • string $name: The name of the counter
  • array $fields: An associative array with the fields to use for the search (field => value)
static callFinder (line 225)

Calls a defined finder (see registerFinder)

  • return: The result as array of database class or NULL if no record was found
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
array callFinder (string $name, array $fields, [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
  • string $name: The name of the finder
  • array $fields: An associative array with the fields to use for the search (field => value)
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
static callIterator (line 257)

Iterate throws a defined finder (see registerFinder)

  • return: The result as database resource or NULL if no record was found
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
resource callIterator (string $name, array $fields, [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
  • string $name: The name of the finder
  • array $fields: An associative array with the fields to use for the search (field => value)
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
static deleteAll (line 811)

Deletes all records that match the given parameters

  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On generic problem
  • access: public
void deleteAll (array $param)
  • array $param: The parameters, as associative array field => value
static findAll (line 440)

Returns all records

  • return: The result as array of database class or NULL if no record was found
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
array findAll ([string $order = NULL], [int $limit = NULL], [int $offset = NULL])
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
static findByPK (line 503)

Get a record using the primary key of the table

  • return: The result as database class or NULL if no record was found
  • throws: myMVC_DatabaseException On Problems
  • access: public
DB-Class findByPK (array $pk)
  • array $pk: The primary key as associative array (field => value)
static getCountAll (line 488)

Returns the count of all records

  • return: The count of all records
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
int getCountAll ()
static iterateAll (line 470)

Iterate all records

  • return: The result as database resource or NULL if no record was found
  • throws: myMVC_InvalidFieldException On invalid field
  • throws: myMVC_DatabaseException On Problems
  • access: public
resource iterateAll ([string $order = NULL], [int $limit = NULL], [int $offset = NULL])
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
Constructor __construct (line 71)

Constructor

  • access: public
myMVC_BaseDB __construct (string $table, array $fields, array $pk, [array $uniques = NULL])
  • string $table: The table on the database
  • array $fields: Associative array with the fields of the table and their check functions
  • array $pk: Array with the PKs of the table. It can contains the key "autoincrement", if the field is an autoincrement field
  • array $uniques: If not NULL, array of arrays, with the unique keys. Every entry is an array with all field for this unique key

Redefinition of:
myMVC_DatabaseConnector::__construct()
Constructor. Initializes the database connection

Redefined in descendants as:
checkFields (line 671)

Checks if all the given data are valid

  • throws: myMVC_InvalidFieldException On invalid field
  • access: protected
void checkFields (array $param, string $type)
  • array $param: The data to check
  • string $type: Check type (save/search)
checkUniques (line 730)

Checks if the unique keys are satisfied

  • throws: myMVC_InvalidFieldException On unsatisfied unique key
  • access: protected
void checkUniques ()
createWhere (line 547)

Creates the WHERE-statement for the SQL query, using parameters

  • return: The WHERE-Statement
  • access: protected
string createWhere (array $param, [array $useLike = array()])
  • array $param: The parameters, as associative array field => value
  • array $useLike: Associative array with the fields that should be search with a LIKE (default: empty)
delete (line 794)

Deletes the record, using the primary key

  • throws: myMVC_DatabaseException On generic problem
  • throws: myMVC_InvalidFieldException On invalid field
  • access: public
void delete ()
findByParameter (line 599)

Get a record from the database, using parameters

  • return: The result as database resource or NULL if no data was found
  • throws: myMVC_DatabaseException On generic problem
  • throws: myMVC_InvalidFieldException On invalid field
  • access: protected
resource findByParameter (array $param, [array $useLike = array()], [string $order = NULL], [int $limit = NULL], [int $offset = NULL])
  • array $param: The parameters, as associative array field => value
  • array $useLike: Associative array with the fields that should be search with a LIKE (default: empty)
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
findBySQLQuery (line 652)

Sends to the database engine an SQL query and get the result

  • return: The result as database resource or NULL if no data was found
  • throws: myMVC_DatabaseException On generic problem
  • access: protected
resource findBySQLQuery (string $sql)
  • string $sql: The SQL query
getCountByParameter (line 634)

Get the count of the records, using parameters

  • return: The count of the record
  • throws: myMVC_DatabaseException On generic problem
  • throws: myMVC_InvalidFieldException On invalid field
  • access: protected
int getCountByParameter (array $param, [array $useLike = array()])
  • array $param: The parameters, as associative array field => value
  • array $useLike: Associative array with the fields that should be search with a LIKE (default: empty)
isRecordUnique (line 688)

Check whether the current record satisfies all unique keys

  • return: true if all unique keys are satisfied, false otherwise
  • access: public
bool isRecordUnique ()
now (line 915)

Returns the current date and time, formatted as for insert in the database

  • return: The current date and time
  • access: public
string now ()
nowFormatted (line 925)

Returns the current date and time, formatted as in the current locale

  • return: The current date and time
  • access: public
string nowFormatted ()
registerCounter (line 326)

Register a new counter method.

This can be called with the method callCounter.

  • throws: myMVC_DatabaseException On Problems
  • access: protected
void registerCounter (string $name, array $fieldsToSearch, [array $fixedFields = array()])
  • string $name: The name of the counter
  • array $fieldsToSearch: An associative array with the fields to use for the search Format of the array: field => "LIKE" or field => "EQUAL"
  • array $fixedFields: An associative array with the "fixed" fields for the search (default: empty) Format of the array: field => value
registerFinder (line 183)

Register a new finder method.

This can be called with the method callFinder or iterateFinder.

  • throws: myMVC_DatabaseException On Problems
  • access: protected
void registerFinder (string $name, array $fieldsToSearch, [array $fixedFields = array()])
  • string $name: The name of the finder
  • array $fieldsToSearch: An associative array with the fields to use for the search Format of the array: field => "LIKE" or field => "EQUAL"
  • array $fixedFields: An associative array with the "fixed" fields for the search (default: empty) Format of the array: field => value
save (line 743)

Save the data. It checks the PK: if the record does not exists, create a new record.

Otherwise it updates it.

  • throws: myMVC_DatabaseException On generic problem
  • throws: myMVC_InvalidFieldException On invalid field
  • access: public
void save ()
saveValues (line 425)

Saves the values of the record

  • access: protected
void saveValues (array $values)
  • array $values: Associative array with the values from the database
sqlExportByParameter (line 836)

Export data as SQL queries, using parameters Exportiert Datensätze als SQL anhand der eingegebenen Parametern

  • return: The export as SQL queries or NULL if no data is available
  • throws: myMVC_DatabaseException On generic problem
  • throws: myMVC_InvalidFieldException On invalid field
  • access: public
string sqlExportByParameter (array $param, [array $useLike = array()], [string $order = NULL], [int $limit = NULL], [int $offset = NULL], [boolean $exportToBrowser = true], [int $separateAfter = 50])
  • array $param: The parameters, as associative array field => value
  • array $useLike: Associative array with the fields that should be search with a LIKE (default: empty)
  • string $order: If not NULL, field(s) to sort data
  • int $limit: If not NULL, maximum of the searched data (useful for paging)
  • int $offset: If not NULL, offset of the searched data (useful for paging)
  • boolean $exportToBrowser: If true (default) data will be exported to the browser If false, data will be exported in the return string
  • int $separateAfter: After $separateAfter lines (default 50) a new SQL header (INSERT INTO...) will be added
__call (line 140)

Dynamic get|set method If the function does not exists (unknown get|set Key), an error will be displayed

  • access: public
void __call ($name $name, $args $args)
  • $name $name: The name of the unknown called function
  • $args $args: The arguments

Inherited Methods

Inherited From myMVC_DatabaseConnector

 myMVC_DatabaseConnector::__construct()
 myMVC_DatabaseConnector::errno()
 myMVC_DatabaseConnector::error()
 myMVC_DatabaseConnector::execute()
 myMVC_DatabaseConnector::executeSelect()
 myMVC_DatabaseConnector::freeResult()
 myMVC_DatabaseConnector::getDatabaseConnection()
 myMVC_DatabaseConnector::getRowsNum()
 myMVC_DatabaseConnector::getValueArrayFromResult()
 myMVC_DatabaseConnector::getValuesFromResult()
 myMVC_DatabaseConnector::quoteSqlString()
 myMVC_DatabaseConnector::quoteSqlStringForLike()

Inherited From myMVC_TypeCheck

 myMVC_TypeCheck::checkAutoIncrementalId()
 myMVC_TypeCheck::checkBoolNotNull()
 myMVC_TypeCheck::checkBoolNull()
 myMVC_TypeCheck::checkDateNotNull()
 myMVC_TypeCheck::checkDateNull()
 myMVC_TypeCheck::checkDateTimeNotNull()
 myMVC_TypeCheck::checkDateTimeNull()
 myMVC_TypeCheck::checkDomainnameNotNull()
 myMVC_TypeCheck::checkDomainnameNull()
 myMVC_TypeCheck::checkEMailNotNull()
 myMVC_TypeCheck::checkEMailNull()
 myMVC_TypeCheck::checkIPNotNull()
 myMVC_TypeCheck::checkIPNull()
 myMVC_TypeCheck::checkMacNotNull()
 myMVC_TypeCheck::checkMacNull()
 myMVC_TypeCheck::checkMaskNotNull()
 myMVC_TypeCheck::checkMaskNull()
 myMVC_TypeCheck::checkNetworkNotNull()
 myMVC_TypeCheck::checkNetworkNull()
 myMVC_TypeCheck::checkSignedIntNotNull()
 myMVC_TypeCheck::checkSignedIntNull()
 myMVC_TypeCheck::checkSignedMediumIntNotNull()
 myMVC_TypeCheck::checkSignedMediumIntNull()
 myMVC_TypeCheck::checkSignedSmallIntNotNull()
 myMVC_TypeCheck::checkSignedSmallIntNull()
 myMVC_TypeCheck::checkSignedTinyIntNotNull()
 myMVC_TypeCheck::checkSignedTinyIntNull()
 myMVC_TypeCheck::checkString255NotNull()
 myMVC_TypeCheck::checkString255Null()
 myMVC_TypeCheck::checkTextNotNull()
 myMVC_TypeCheck::checkTextNull()
 myMVC_TypeCheck::checkTimeNotNull()
 myMVC_TypeCheck::checkTimeNull()
 myMVC_TypeCheck::checkUnsignedIntNotNull()
 myMVC_TypeCheck::checkUnsignedIntNull()
 myMVC_TypeCheck::checkUnsignedMediumIntNotNull()
 myMVC_TypeCheck::checkUnsignedMediumIntNull()
 myMVC_TypeCheck::checkUnsignedSmallIntNotNull()
 myMVC_TypeCheck::checkUnsignedSmallIntNull()
 myMVC_TypeCheck::checkUnsignedTinyIntNotNull()
 myMVC_TypeCheck::checkUnsignedTinyIntNull()
 myMVC_TypeCheck::checkURLNotNull()
 myMVC_TypeCheck::checkURLNull()

Documentation generated on Thu, 05 Jan 2017 12:47:13 +0100 by phpDocumentor 1.4.4