Class As_Database

Description

This is a cleaned up version of the Database (MySQL at the moment) in use at Academic Superstore.

Most notably, all the "doSomething" functions are now "something" and all the backward compatibility cruft for A.S.'s legacy Persistent class have been removed.

This file is released under the FreeBSD license.

Located in /as_database/As_Database.class.php (line 15)


	
			
Direct descendents
Class Description
CoughAsDatabase Cough DAL (Database Adapter Layer) for the "as_database" module.
Class Constant Summary
Variable Summary
mixed $clientFlags
mixed $connection
mixed $dbHost
mixed $dbName
mixed $dbPassword
mixed $dbPort
mixed $dbUser
boolean $inTransaction
mixed $logQueries
mixed $query
mixed $queryLog
Method Summary
As_Database __construct ( $dbName, [ $dbHost = 'localhost'], [ $dbUser = 'nobody'], [ $dbPassword = ''], [ $dbPort = 3306], [ $clientFlags = 0])
void __destruct ()
void clearQueryLog ()
void commit ()
void delete ( $tableName,  $where)
void escape ( $value)
void generateError ( $errorType, [ $sqlError = ''])
void generateSet ( $fields, [ $quotes = NULL])
void generateWhere ([ $where = array()], [ $quotes = NULL], [ $prefix = 'WHERE'])
void getAffectedRows ()
string getError ()
void getFoundRows ()
void getInsertID ()
void getQuery ()
void getQueryLog ()
void getQueryLogTime ()
void getResultObjectFromResource ( $resource)
void getSecondsBehindMaster ( $master)
void getTestForMatch ( $value)
void getTestForNonMatch ( $value)
void initConnection ()
mixed insert (string $tableName, array $fields, [array $quotes = null], [string $dbName = ''], [string $escape = true])
void insertMultiple ( $tableName,  $fields,  $data, [ $quotes = NULL], [ $dbName = ''], [ $escape = true])
void insertOnDupUpdate ( $tableName,  $fields, [ $quotes = NULL])
void insertOrCancel ( $tableName,  $fields, [ $quotes = NULL],  $where)
void insertOrUpdate ( $tableName,  $fields, [ $quotes = NULL],  $where)
void isInTransaction ()
void query ( $sql)
void quote ( $value)
void replace ( $tableName,  $fields, [ $quotes = NULL])
void replaceMultiple ( $tableName,  $fields,  $data, [ $quotes = NULL], [ $dbName = ''], [ $escape = true])
the result (string $sql)
void rollback ()
void select ( $tableName, [ $fields = array()], [ $where = array()])
void selectDB ( $dbName)
void startLoggingQueries ([ $logBacktraces = false])
void update ( $tableName,  $fields, [ $quotes = NULL],  $where, [ $whereQuotes = NULL], [ $dbName = ''], [ $escape = true])
Variables
mixed $clientFlags = 0 (line 32)
  • access: protected
mixed $connection (line 33)
  • access: protected
mixed $dbHost = null (line 27)
  • access: protected
mixed $dbName = null (line 28)
  • access: protected
mixed $dbPassword = null (line 30)
  • access: protected
mixed $dbPort (line 31)
  • access: protected
mixed $dbUser = null (line 29)
  • access: protected
boolean $inTransaction = false (line 42)

Whether or not we are currently in a transaction.

string $logBacktraces = false (line 57)

Whether or not to log backtraces when logging queries

  • access: protected
mixed $logQueries = false (line 50)

Whether or not to log all queries (to variable)

  • author: Anthony Bush
  • access: protected
mixed $query (line 34)
  • access: protected
mixed $queryLog = array() (line 65)

Logged queries since logQueries was turned on

  • author: Anthony Bush
  • access: protected
Methods
Constructor __construct (line 67)
  • access: public
As_Database __construct ( $dbName, [ $dbHost = 'localhost'], [ $dbUser = 'nobody'], [ $dbPassword = ''], [ $dbPort = 3306], [ $clientFlags = 0])
  • $dbName
  • $dbHost
  • $dbUser
  • $dbPassword
  • $dbPort
  • $clientFlags
Destructor __destruct (line 80)
  • access: public
void __destruct ()
clearQueryLog (line 607)
  • access: public
void clearQueryLog ()
commit (line 525)

Commit a transaction.

void commit ()
delete (line 481)
  • access: public
void delete ( $tableName,  $where)
  • $tableName
  • $where
escape (line 131)
  • access: public
void escape ( $value)
  • $value
generateError (line 548)
  • access: protected
void generateError ( $errorType, [ $sqlError = ''])
  • $errorType
  • $sqlError
generateSet (line 422)
  • access: public
void generateSet ( $fields, [ $quotes = NULL])
  • $fields
  • $quotes
generateWhere (line 433)
  • access: public
void generateWhere ([ $where = array()], [ $quotes = NULL], [ $prefix = 'WHERE'])
  • $where
  • $quotes
  • $prefix
getAffectedRows (line 191)
  • access: public
void getAffectedRows ()
getError (line 202)

Returns the error message from the last query run.

  • author: Anthony Bush
  • since: 2008-04-16
  • access: public
string getError ()
getFoundRows (line 212)

Returns the number of found rows from the last run query.

Make sure to put SQL_CALC_FOUND_ROWS immediately after the SELECT in order for this to work.

  • access: public
void getFoundRows ()
getInsertID (line 489)
  • access: public
void getInsertID ()
getQuery (line 589)
  • access: public
void getQuery ()
getQueryLog (line 603)
  • access: public
void getQueryLog ()
getQueryLogTime (line 611)
  • access: public
void getQueryLogTime ()
getResultObjectFromResource (line 166)
  • access: protected
void getResultObjectFromResource ( $resource)
  • $resource

Redefined in descendants as:
getSecondsBehindMaster (line 105)
  • access: public
void getSecondsBehindMaster ( $master)
  • $master
getTestForMatch (line 450)
  • access: public
void getTestForMatch ( $value)
  • $value
getTestForNonMatch (line 458)
  • access: public
void getTestForNonMatch ( $value)
  • $value
getUniqueQueryLog (line 629)

Like the query log, but it rolls up all duplicate queries into only one entry in the array. It adds a count value equal to the number of times the query was run, and the time value is equal to the total time of each query run.

  • return: in format of [sql] => array([time] => float, [count] => integer)
  • author: Anthony Bush
  • since: 2007-09-07
  • access: public
hash getUniqueQueryLog ()
initConnection (line 96)
  • access: public
void initConnection ()
insert (line 230)

Perform an INSERT.

This function is Persistent Compatible.

  • return: - last inserted ID
  • author: Anthony Bush
  • author: Matt Schiros
  • access: public
mixed insert (string $tableName, array $fields, [array $quotes = null], [string $dbName = ''], [string $escape = true])
  • string $tableName: - the table name to INSERT INTO.
  • array $fields: - an array of field_name => field_value pairs to be inserted.
  • array $quotes: - an array of field_name => true/false pairs of which field_values should be quoted/escaped.;
  • string $dbName: - optional database name to insert into (for Persistent compatibility).
  • string $escape: - optional specification of whether or not to escape quoted values (for Persistent compatibility).
insertMultiple (line 254)
  • access: public
void insertMultiple ( $tableName,  $fields,  $data, [ $quotes = NULL], [ $dbName = ''], [ $escape = true])
  • $tableName
  • $fields
  • $data
  • $quotes
  • $dbName
  • $escape
insertOnDupUpdate (line 416)

Like insertOrUpdate, except a WHERE clause is not required

Using this function will keep DUPLICATE KEY errors at bay for when you don't have access to the primary key. If you DO have access to the primary key, you can use insertOrUpdate and pass in the key values as the $where parameter.

  • author: Anthony Bush
  • since: 2007-02-24
  • access: public
void insertOnDupUpdate ( $tableName,  $fields, [ $quotes = NULL])
  • $tableName
  • $fields
  • $quotes
insertOrCancel (line 379)
  • access: public
void insertOrCancel ( $tableName,  $fields, [ $quotes = NULL],  $where)
  • $tableName
  • $fields
  • $quotes
  • $where
insertOrUpdate (line 390)
  • access: public
void insertOrUpdate ( $tableName,  $fields, [ $quotes = NULL],  $where)
  • $tableName
  • $fields
  • $quotes
  • $where
isInTransaction (line 531)
  • access: public
void isInTransaction ()
query (line 138)
  • access: public
void query ( $sql)
  • $sql
quote (line 115)
  • access: public
void quote ( $value)
  • $value
replace (line 337)
  • access: public
void replace ( $tableName,  $fields, [ $quotes = NULL])
  • $tableName
  • $fields
  • $quotes
replaceMultiple (line 296)
  • access: public
void replaceMultiple ( $tableName,  $fields,  $data, [ $quotes = NULL], [ $dbName = ''], [ $escape = true])
  • $tableName
  • $fields
  • $data
  • $quotes
  • $dbName
  • $escape
result (line 182)

result function

Execute a database query and retrieve the value of the first field in the result

  • return: value of the first field in the result (or false if none exists?)
  • access: public
  • name: result
the result (string $sql)
  • string $sql: sql statement to execute
rollback (line 542)

Rollback a non-committed transaction.

void rollback ()
select (line 466)
  • access: public
void select ( $tableName, [ $fields = array()], [ $where = array()])
  • $tableName
  • $fields
  • $where
selectDB (line 87)
  • access: public
void selectDB ( $dbName)
  • $dbName
startLoggingQueries (line 593)
  • access: public
void startLoggingQueries ([ $logBacktraces = false])
  • $logBacktraces
startTransaction (line 512)

Starts a transaction.

Example Usage:

$db->startTransaction(); try { $db->query($sql1); $db->query($sql2); $db->query($sql3); $db->commit(); } catch (Exception $e) { $db->rollback(); }

void startTransaction ()
stopLoggingQueries (line 598)
  • access: public
void stopLoggingQueries ()
update (line 358)
  • access: public
void update ( $tableName,  $fields, [ $quotes = NULL],  $where, [ $whereQuotes = NULL], [ $dbName = ''], [ $escape = true])
  • $tableName
  • $fields
  • $quotes
  • $where
  • $whereQuotes
  • $dbName
  • $escape
Class Constants
ERROR_CONNECT = 1 (line 17)
ERROR_DB_SELECT = 2 (line 18)
ERROR_INSERT = 3 (line 19)
ERROR_QUERY = 5 (line 21)
ERROR_UPDATE = 4 (line 20)
INSERT = 2 (line 25)
UPDATE = 1 (line 24)

Documentation generated on Wed, 12 Nov 2008 21:56:09 -0600 by phpDocumentor 1.4.0