com.lokorin.lokorin.lib
[ class tree: com.lokorin.lokorin.lib ] [ index: com.lokorin.lokorin.lib ] [ all elements ]

Class: DataBase

Source Location: /_includes/lib_db.php

Class Overview


Describes a database abstraction. The abstraction maintains a connection which is instance specific. Hence it is recommended that only one global instance is used.


Author(s):

  • Andreas Launila

Variables

Methods



Class Details

[line 73]
Describes a database abstraction. The abstraction maintains a connection which is instance specific. Hence it is recommended that only one global instance is used.



Tags:

author:  Andreas Launila


[ Top ]


Class Variables

$connection =

[line 78]

The database connection to use.



Tags:

access:  private

Type:   mysqlconnection


[ Top ]

$instance =

[line 100]

The one and only instance of the class.



Tags:

static:  
access:  private

Type:   DB


[ Top ]

$queryCount =

[line 89]

The number of queries that have been performed by the database. 0 means that no queries have been performed.



Tags:

access:  private

Type:   integer


[ Top ]

$queryDuration =

[line 95]

The number of milliseconds that have elapsed while waiting for the database to complete a query. This is the sum of all query times.



Tags:

access:  private

Type:   integer


[ Top ]

$queue = array()

[line 83]

Contains any queued queries.



Tags:

access:  private

Type:   array


[ Top ]



Class Methods


constructor __construct [line 116]

DataBase __construct( )

Constructor for DB.



Tags:

access:  private


[ Top ]

method buildDeleteQuery [line 264]

string buildDeleteQuery( string $tableName, string $sqlSelector)

Builds and executes a delete query for the specified table using the specified values.



Tags:

return:  The resulting query.
access:  public


Parameters:

string   $tableName   The name of the table to delete rows from.
string   $sqlSelector   An sql selector to tell the query what rows should be affected by the query.

[ Top ]

method buildInsertQuery [line 219]

string buildInsertQuery( string $tableName, [array $insertFields = array()])

Builds an insert query based on the specified table and values.



Tags:

return:  The resulting query.
access:  public


Parameters:

string   $tableName   The name of the table that the values should be inserted in.
array   $insertFields   An array containing the values that should be used to build the insert query. The key should be the field name and the value should be the connected value for that field.

[ Top ]

method buildSqlSelector [line 426]

string buildSqlSelector( array $fieldValues)

Builds a sql selector from specified field values.



Tags:

return:  A sqlSelector that specifies rows whos field have the specified values. Returns a boolean false if the argument is not an array.
access:  public


Parameters:

array   $fieldValues   An array containing the specified values. The key is the field name, the value is the value that the field should have.

[ Top ]

method buildUpdateQuery [line 298]

string buildUpdateQuery( string $tableName, [array $updateFields = array()], [string $sqlSelector = ''])

Builds an update query for the specified table using the specified values.



Tags:

return:  The resulting query.
access:  public


Parameters:

string   $tableName   The name of the table to update.
array   $updateFields   The fields that should be updated for all affected rows. The key is the field's name and the value is the new value that the field should have.
string   $sqlSelector   An optional selector to specify the resulting selector even more. The parameter is appended onto the end of the constructed selector.

[ Top ]

method clearQueue [line 484]

void clearQueue( )

Clears the queue, removing all currently queued queries wihtout executing them.



Tags:

access:  public


[ Top ]

method connectToDb [line 124]

void connectToDb( )

Connects to mysql and selects the correct databse.



Tags:

access:  private


[ Top ]

method ensureConnected [line 137]

void ensureConnected( )

Ensures that there is a active valid connection the the database. Id there is an active and valid connection then nothing is done, otherwise a connection is created.



Tags:

access:  private


[ Top ]

method escape [line 176]

mixed escape( mixed $value)

Escapes any special characters in the specified value. The result is also quoted if it is not numeric. All field values should be run through this function to ensure security.



Tags:

return:  The escaped version of the value, with appropriate quotes if it is not numeric.
access:  public


Parameters:

mixed   $value   The value that should be escaped.

[ Top ]

method flushQueue [line 465]

void flushQueue( )

Flushes the queue, executing all queries in it in the order that they were inserted and then clearing it.



Tags:

access:  public


[ Top ]

method getElapsedQueryTime [line 504]

integer getElapsedQueryTime( )

Gets the number of milliseconds that the database has spent processing queries during the page request.



Tags:

return:  A non-negative number, e.g. 10 means that 10 milliseconds have been spent on processing queries.
access:  public


[ Top ]

method getInstance [line 106]

DB getInstance( )

Gets the one and only instance of the class.



Tags:

return:  The one and only instance.
static:  
access:  public


[ Top ]

method getLastInsertId [line 448]

integer getLastInsertId( )

Gets the last generated identifier on a per-connection basis.



Tags:

return:  The last generated identifier.
access:  public


[ Top ]

method getQueryCount [line 494]

integer getQueryCount( )

Gets the number of queries that have been performed by the database during the page request.



Tags:

return:  A non-negative number, 0 means that no queries have been performed.
access:  public


[ Top ]

method getQueueSize [line 476]

integer getQueueSize( )

Gets the number of queries in the queue.



Tags:

return:  A positive number.
access:  public


[ Top ]

method query [line 148]

mysqlresult query( string $query)

Performs a specified query on the database.



Tags:

return:  The result resource of the query.
access:  public


Parameters:

string   $query   The query that should be performed.

[ Top ]

method queryCount [line 411]

integer queryCount( string $tableName, [string $sqlSelector = ''])

Gets the number of rows that matches specified conditions.



Tags:

return:  The number of rows that satisfy the specified conditions.
access:  public


Parameters:

string   $tableName   The table name to count from.
string   $sqlSelector   An optional sql selector for the query. This can be used to count a subset of the rows. The default is that all rows are counted.

[ Top ]

method queryDelete [line 246]

boolean queryDelete( string $tableName, [string $sqlSelector = ''])

Builds and executes a delete query on the specified table using the specified values.



Tags:

return:  True if the query was executed successfully, false otherwise.
access:  public


Parameters:

string   $tableName   The name of the table to delete rows from.
string   $sqlSelector   An sql selector to tell the query what rows should be affected by the query.

[ Top ]

method queryInsert [line 206]

boolean queryInsert( string $tableName, [array $insertFields = array()])

Builds and executes an insert query based on the specified table and values.



Tags:

return:  True if the query was executed successfully, false otherwise.
access:  public


Parameters:

string   $tableName   The name of the table that the query should be executed on.
array   $insertFields   An array containing the values that should be used to build the insert query. The key should be the field name and the value should be the connected value for that field.

[ Top ]

method querySelect [line 323]

array querySelect( string $tableName, array $fields, [string $sqlSelector = ''])

Selects specific table fields from a specific table. The select operation can also specify an optional sql selector.



Tags:

return:  The selected rows and fields. The array contains one array per row. Each of those array rows contain keys with the specified field names along with the connected values. If no values were found then an empty array will be returned.
access:  public


Parameters:

string   $tableName   The name of the table to select from.
array   $fields   An array with the names of the fields that should be selected.
string   $sqlSelector   Optional sql selector for the query.

[ Top ]

method querySelectAll [line 365]

array querySelectAll( string $tableName, [string $sqlSelector = ''])

Selects all table fields from a specific table. The select operation can also specify an optional sql selector.



Tags:

return:  The selected rows and fields. The array contains one array per row. Each of those array rows contain keys with the field names along with the connected values. If no values were found then an empty array will be returned.
access:  public


Parameters:

string   $tableName   The name of the table to select from.
string   $sqlSelector   Optional sql selector for the query.

[ Top ]

method querySelectFirst [line 393]

mixed querySelectFirst( string $tableName, string $field, string $sqlSelector)

Selects the first value found in a specified field in a specified table that satisfies an sql selector.



Tags:

return:  The first value found that specifies all paramaters.
access:  public
throws:  NoSuchElementException If nor row matches the sql selector.


Parameters:

string   $tableName   The name of the table to select from.
string   $field   The name of the table field from which the value should be selected.
string   $sqlSelector   An sql selector for the query. The selector specifies which rows that should be selected and which should be ignored.

[ Top ]

method queryUpdate [line 281]

boolean queryUpdate( string $tableName, [array $updateFields = array()], [string $sqlSelector = ''])

Builds and executes an update query on the specified table using the specified values and selector.



Tags:

return:  True if the query was executed successfully, false otherwise.
access:  public


Parameters:

string   $tableName   The name of the table to update.
array   $updateFields   The fields that should be updated for all affected rows. The key is the field's name and the value is the new value that the field should have.
string   $sqlSelector   An optional selector to tell the query what rows should be affected by the query. The default is that all rows are affected.

[ Top ]

method queueQuery [line 457]

void queueQuery( string $query)

Puts a specified query at the end of the queue.



Tags:

access:  public


Parameters:

string   $query   The query that should be added to the queue.

[ Top ]


Documentation generated on Sun, 16 Apr 2006 21:03:17 +0200 by phpDocumentor 1.3.0RC4