Class MySQLDatabase

Description

A MySQLDatabase class provides the tools to connect, query, etc., a MySQL database.

MySQL (at least as of 4.0.17) does not support nested transations. Begining a transaction after one is started will commit the previous transaction. This is pretty stupid behavior, so this class maintains a count of begin and commit calls and only runs the outer begin/commit/rollback statements. This allows applications coded for PostgreSQL/Oracle-style nested transactions to operate in MySQL.

  • version: $Id: MySQLDatabase.class.php,v 1.37 2007/09/05 21:39:00 adamfranco Exp $
  • license: GNU General Public License (GPL)
  • copyright: Copyright © 2005, Middlebury College

Located in /harmoni/core/DBHandler/MySQL/MySQLDatabase.class.php (line 37)

DatabaseAbstract
   |
   --MySQLDatabase
Variable Summary
Method Summary
integer MySQLDatabase (string $dbHost, string $dbName, string $dbUser, string $dbPass)
mixed connect ()
boolean disconnect ()
ref fromDBDate (mixed $value)
string generateSQL (object $query)
string getStringName ()
array getTableList ()
boolean isConnected ()
mixed pConnect ()
mixed query (Query $query)
boolean selectDatabase (string $database)
mixed toDBDate (DateAndTime $dateAndTime)
mixed _query (string $query)
Variables
string $_dbHost (line 47)

The hostname of the database, i.e. myserver.mydomain.edu.

The hostname of the database, i.e. myserver.mydomain.edu.

  • var: The hostname of the database, i.e. myserver.mydomain.edu.
  • access: private
string $_dbName (line 55)

The name of the default database to use.

The name of the default database to use.

  • var: The name of the default database to use.
  • access: private
string $_dbPass (line 71)

The password for $_dbUser with which to connect to the database.

The password for $_dbUser with which to connect to the database.

  • var: The password for $_dbUser with which to connect to the database.
  • access: private
string $_dbUser (line 63)

The username with which to connect to the database.

The username with which to connect to the database.

  • var: The username with which to connect to the database.
  • access: private
integer $_failedQueries (line 110)

The total number of failed queries executed since the last call to connect().

The total number of failed queries executed since the last call to connect().

  • var: The total number of failed queries executed since the last call to connect().
  • access: private
boolean $_isConnectionPersistant (line 92)

Persistant connections can not be closed or have a new link forced, so this property is necessary for determining whether or not a mysql_select_db() is needed before queries to ensure that the proper database is selected.

  • since: 8/18/05
  • access: private
mixed $_linkId (line 81)

Stores the current connection's link identifier.

If a connection is open, this stores the connection's identifier. Otherwise, it stores FALSE.

  • var: If a connection is open, this stores the connection's identifier. Otherwise, it stores FALSE.
  • access: private
integer $_successfulQueries (line 101)

The total number of successful queries executed since the last call to connect().

The total number of failed queries executed since the last call to connect().

  • var: The total number of failed queries executed since the last call to connect().
  • access: private
boolean $_supportsTransactions = null (line 117)

TRUE if this database supports transactions.

  • access: private
Methods
Constructor MySQLDatabase (line 128)

Creates a new database connection.

  • return: The index of the new database
  • access: public
integer MySQLDatabase (string $dbHost, string $dbName, string $dbUser, string $dbPass)
  • string $dbHost: The hostname for the database, i.e. myserver.mydomain.edu.
  • string $dbName: The name of the default database to use.
  • string $dbUser: The username with which to connect to the database.
  • string $dbPass: The password for $_dbUser with which to connect to the database.
beginTransaction (line 576)

Begin a transaction.

  • since: 3/9/05
  • access: public
void beginTransaction ()
commitTransaction (line 597)

Commit a transaction. This will roll-back changes if errors occured in the transaction block.

  • since: 3/9/05
  • access: public
void commitTransaction ()
connect (line 186)

Connects to the database.

Connects to the database.

  • return: The connection's link identifier, if successful; False, otherwise.
  • access: public
mixed connect ()
disconnect (line 400)

Disconnects from the database.

Disconnects from the database.

  • return: True, if successful; False, otherwise.
  • access: public
boolean disconnect ()
fromDBDate (line 529)

Converts a database datetime/timestamp/time value (that has been fetched from the db) to a DateAndTime object.

Depending whether the value was fecthed from a datetime, date or timestamp column, $value could have the following two formats: 'YYYY-MM-DD HH:MM:SS' for datetime 'YYYY-MM-DD' for date For a timestamp, $value could be any of the following depending on the column size. TIMESTAMP(14) YYYYMMDDHHMMSS TIMESTAMP(12) YYMMDDHHMMSS - NOT SUPPORTED TIMESTAMP(10) YYMMDDHHMM - NOT SUPPORTED TIMESTAMP(8) YYYYMMDD TIMESTAMP(6) YYMMDD - NOT SUPPORTED TIMESTAMP(4) YYMM - NOT SUPPORTED TIMESTAMP(2) YY - NOT SUPPORTED

From MySQL version 4.1, TIMESTAMP is returned as a string with the format 'YYYY-MM-DD HH:MM:SS' and different timestamp lengths are no longer supported.

WARNING: Due to the ambiguity of 2-digit years, timestamp formats that use 2-digit years are not supported.

  • return: object The DateAndTime object.
  • access: public
ref fromDBDate (mixed $value)
  • mixed $value: A database datetime/timestamp/time value (that has been fetched from the db).
generateSQL (line 327)

Answer the string SQL for the query

  • since: 11/14/06
  • access: public
string generateSQL (object $query)
  • object $query
getNumberFailedQueries (line 450)

Returns the total number of failed queries executed since the last call to connect().

Returns the total number of failed queries executed since the last call to connect().

  • return: The total number of failed queries executed since the last call to connect().
  • access: public
integer getNumberFailedQueries ()
getNumberSuccessfulQueries (line 438)

Returns the total number of successful queries executed since the last call to connect().

Returns the total number of successful queries executed since the last call to connect().

  • return: The total number of successful queries executed since the last call to connect().
  • access: public
integer getNumberSuccessfulQueries ()
getStringName (line 153)

Returns a short string name for this database type. Example: 'MySQL'

  • access: public
string getStringName ()
getTableList (line 162)

Returns a list of the tables that exist in the currently connected database.

  • access: public
array getTableList ()
isConnected (line 423)

Indicates whether there is an open connection to the database.

Indicates whether there is an open connection to the database.

  • return: True if there is an open connection to the database; False, otherwise.
  • access: public
boolean isConnected ()
pConnect (line 228)

Makes a persistent database connection.

Makes a persistent database connection.

  • return: The connection's link identifier, if successful; False, otherwise.
  • access: public
mixed pConnect ()
query (line 270)

Executes an SQL query.

Executes an SQL query. The method is passed a query object, which it converts to a SQL query string using the appropriate SQLGenerator object.

  • return: The appropriate QueryResult object. If the query failed, it would return NULL.
  • access: public
mixed query (Query $query)
  • object Query $query: A Query object from which the SQL query will be constructed.
rollbackTransaction (line 617)

Roll-back a transaction manually instead of committing

  • since: 3/9/05
  • access: public
void rollbackTransaction ()
selectDatabase (line 462)

This method selects the default database to use in queries.

  • return: True, if successful; False, otherwise.
  • access: public
boolean selectDatabase (string $database)
  • string $database: database The name of the default database.
supportsTransactions (line 545)

Return TRUE if this database supports transactions.

  • since: 3/9/05
  • access: public
boolean supportsTransactions ()
toDBDate (line 489)

Converts a DateAndTime object to a proper datetime/timestamp/time representation for this Database.

The easiest way to convert is to create an integer (or a string, choose which one you think is better, MySQL accepts both, but make sure to document) in the following format: YYYYMMDDHHMMSS. You can pass this to a MySQL datetime or timestamp column types and it gets parsed automatically by MySQL.

  • return: A proper datetime/timestamp/time representation for this Database.
  • access: public
mixed toDBDate (DateAndTime $dateAndTime)
  • ref $dateAndTime: object DateAndTime The DateAndTime object to convert.
_query (line 340)

Executes an SQL query.

Executes an SQL query.

  • return: For a SELECT statement, a resource identifier, if successful; For INSERT, DELETE, UPDATE statements, TRUE if successful; for all: FALSE, if not successful.
  • access: private
mixed _query (string $query)
  • string $query: The SQL query string.

Inherited Methods

Inherited From DatabaseAbstract

DatabaseAbstract::getConnectionErrorInfo()

Documentation generated on Wed, 19 Sep 2007 10:25:10 -0400 by phpDocumentor 1.3.0RC3