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

Class: DB

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 62]
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 67]

The database connection to use.



Tags:

access:  private

Type:   mysqlconnection


[ Top ]

$instance =

[line 77]

The one and only instance of the class.



Tags:

static:  
access:  private

Type:   DB


[ Top ]

$queue = array()

[line 72]

Contains any queued queries.



Tags:

access:  private

Type:   array


[ Top ]



Class Methods


constructor __construct [line 93]

DB __construct( )

Constructor for DB.



Tags:

access:  private


[ Top ]

method buildDeleteQuery [line 224]

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 179]

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 386]

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 258]

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 444]

void clearQueue( )

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



Tags:

access:  public


[ Top ]

method connectToDb [line 100]

void connectToDb( )

Connects to mysql and selects the correct databse.



Tags:

access:  private


[ Top ]

method ensureConnected [line 113]

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 142]

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 425]

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 getInstance [line 83]

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 408]

integer getLastInsertId( )

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



Tags:

return:  The last generated identifier.
access:  public


[ Top ]

method getQueueSize [line 436]

integer getQueueSize( )

Gets the number of queries in the queue.



Tags:

return:  A positive number.
access:  public


[ Top ]

method query [line 124]

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 371]

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 206]

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 166]

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 283]

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 325]

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 353]

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 241]

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 417]

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 Tue, 10 Jan 2006 17:06:26 +0100 by phpDocumentor 1.3.0RC4