Comments: on this page. Click to read or post your own.

Class PDODatabase

Description

PDO (general database) connector class.

Located in /sapphire/core/model/PDODatabase.php (line 7)

Object
   |
   --Database
      |
      --PDODatabase
Method Summary
PDODatabase __construct (parameters $parameters)
void affectedRows ()
void alterField (string $table, string $field, string $type)
void alterIndex (string $tableName, string $indexName, string $indexSpec)
void. alterTable ( $table, [string $newFields = null], [string $newIndexes = null], [string $alteredFields = null], [string $alteredIndexes = null], string $tableName)
boolean checkAndRepairTable ( $tableName)
boolean createDatabase (string $connect, string $username, string $password, string $database)
void createField (string $tableName, string $fieldName, string $fieldSpec)
void createIndex (string $tableName, string $indexName, string $indexSpec)
void. createTable ( $tableName, [ $fields = null], [ $indexes = null])
void databaseExists ( $name)
void fieldList ( $table, string $able)
string getConnect (array $parameters)
string getDatabaseServer ()
int getGeneratedID ( $table)
int getNextID ( $table)
float getVersion ()
void indexList ( $table, string $able)
bool isActive ()
result query ( $sql, [ $errorLevel = E_USER_ERROR])
void. renameTable (string $oldTableName, string $newTableName)
boolean runTableCheckCommand (string $sql)
void selectDatabase ( $dbname)
void tableList ()
Variables
Methods
Constructor __construct (line 50)

Connect to a database (MySQL, PostgreSQL, or MS SQL).

  • access: public
PDODatabase __construct (parameters $parameters)
  • parameters $parameters: An map of parameters, which should include:
    • database: The database to connect with
    • server: The server, eg, localhost
    • port: The port on which the server is listening (optional)
    • instance: Instance of the server, MS SQL only (optional)
    • username: The username to log on with
    • password: The password to log on with
    • database: The database to connect to

Redefinition of:
Object::__construct()
affectedRows (line 646)

Return the number of rows affected (DELETE, INSERT, or UPDATE) by the previous operation.

  • access: public
void affectedRows ()
alterField (line 413)

Change the database type of the given field.

  • access: public
void alterField (string $table, string $field, string $type)
  • string $table: The table where to change the field.
  • string $field: The field to change.
  • string $type: The new type of the field
alterIndex (line 456)

Alter an index on a table.

  • access: public
void alterIndex (string $tableName, string $indexName, string $indexSpec)
  • string $tableName: The name of the table.
  • string $indexName: The name of the index.
  • string $indexSpec: The specification of the index, see Database::requireIndex() for more details.
alterTable (line 317)

Alter fields and indexes in existing table.

  • access: public
void. alterTable ( $table, [string $newFields = null], [string $newIndexes = null], [string $alteredFields = null], [string $alteredIndexes = null], string $tableName)
  • string $tableName: The name of the table.
  • string $newFields: Fields to add.
  • string $newIndexes: Indexes to add.
  • string $alteredFields: Fields to change.
  • string $alteredIndexes: Indexes to change.
  • $table

Redefinition of:
Database::alterTable()
Alter a table's schema.
checkAndRepairTable (line 364)

Checks a table's integrity and repairs it if necessary - only available in MySQL, not supported in PostgreSQL and MS SQL.

  • var: The name of the table.
  • return: Return true if the table has integrity after the method is complete.
  • access: public
boolean checkAndRepairTable ( $tableName)
  • $tableName
createDatabase (line 230)

Create the database and connect to it. This can be called if the initial database connection is not successful because the database does not exist.

  • return: Returns true if successful
  • todo: This shouldn't take any arguments; it should take the information given in the constructor instead.
  • access: public
boolean createDatabase (string $connect, string $username, string $password, string $database)
  • string $connect: Connection string
  • string $username: Database username
  • string $password: Database Password
  • string $database: Database to which to create

Redefinition of:
Database::createDatabase()
Create the database and connect to it. This can be called if the initial database connection is not successful because the database does not exist.
createField (line 401)

Add the given field to the given table.

  • access: public
void createField (string $tableName, string $fieldName, string $fieldSpec)
  • string $tableName: The name of the table on which to create the field.
  • string $fieldName: The field to create.
  • string $fieldSpec: The datatype of the field.

Redefinition of:
Database::createField()
Create a new field on a table.
createIndex (line 444)

Create an index on a table.

  • access: public
void createIndex (string $tableName, string $indexName, string $indexSpec)
  • string $tableName: The name of the table.
  • string $indexName: The name of the index.
  • string $indexSpec: The specification of the index, see Database::requireIndex() for more details.
createTable (line 282)

Create a new table with an integer primary key called ID.

  • var: The name of the table.
  • access: public
void. createTable ( $tableName, [ $fields = null], [ $indexes = null])
  • $tableName
  • $fields
  • $indexes

Redefinition of:
Database::createTable()
Create a new table.
databaseExists (line 246)

Returns true if the named database exists.

  • access: public
void databaseExists ( $name)
  • $name
fieldList (line 469)

Get a list of all the fields for the given table.

The results are not totally equal for all databases (for example collations are handled very differently, PostgreSQL disregards zerofill,...) but as close as possible and necessary.

  • access: public
void fieldList ( $table, string $able)
  • string $able: Table of which to show the fields. Returns a map of field name => field spec.
  • $table

Redefinition of:
Database::fieldList()
Get a list of all the fields for the given table.
getConnect (line 72)

Build the connection string from input.

  • return: The connection string.
  • access: public
string getConnect (array $parameters)
  • array $parameters: The connection details.

Redefinition of:
Database::getConnect()
Build the connection string from input
getDatabaseServer (line 147)

Get the database server, namely mysql, pgsql, or mssql.

  • access: public
string getDatabaseServer ()
getGeneratedID (line 190)

Get the ID for the next new record for the table.

Get the autogenerated ID from the previous INSERT query. Simulate mysql_insert_id by fetching the highest ID as there is no other reliable method across databases.

  • access: public
int getGeneratedID ( $table)
  • $table

Redefinition of:
Database::getGeneratedID()
Get the autogenerated ID from the previous INSERT query.
getNextID (line 203)

OBSOLETE: Get the ID for the next new record for the table.

  • var: The name od the table.
  • access: public
int getNextID ( $table)
  • $table
getVersion (line 126)

Get the database version.

  • access: public
float getVersion ()
indexList (line 564)

Get a list of all the indexes for the given table.

  • access: public
void indexList ( $table, string $able)
  • string $able: Table of which to show the indexes. Returns a map of indexes.
  • $table
isActive (line 215)

Determine if the the table is active.

  • access: public
bool isActive ()

Redefinition of:
Database::isActive()
Check if the connection to the database is active.
query (line 156)

Query the database.

  • var: The query to be issued to the database.
  • return: Return the result of the quers (if any).
  • access: public
result query ( $sql, [ $errorLevel = E_USER_ERROR])
  • $sql
  • $errorLevel

Redefinition of:
Database::query()
Execute the given SQL query.
renameTable (line 354)

Rename an existing table, the TO is necessary for PostgreSQL and MS SQL.

  • access: public
void. renameTable (string $oldTableName, string $newTableName)
  • string $oldTableName: The name of the existing table.
  • string $newTableName: How the table should be named from now on.

Redefinition of:
Database::renameTable()
Rename a table.
runTableCheckCommand (line 385)

Helper function used by checkAndRepairTable.

  • return: Returns if the query returns a successful result.
  • access: protected
boolean runTableCheckCommand (string $sql)
  • string $sql: Query to run.
selectDatabase (line 262)

Switches to the given database.

Simply switching database in PDO is not possible, you need to create a new PDO object

  • access: public
void selectDatabase ( $dbname)
  • $dbname
supportsCollations (line 106)

Returns true if this database supports collations

  • access: public
void supportsCollations ()
tableList (line 620)

Returns a list of all the tables in the database.

Table names will all be in lowercase. Returns a map of a table.

  • access: public
void tableList ()

Redefinition of:
Database::tableList()
Returns a list of all tables in the database.

Inherited Methods

Inherited From Database

Database::alteration_message()
Database::alterTable()
Database::beginSchemaUpdate()
Database::createDatabase()
Database::createField()
Database::createTable()
Database::databaseError()
Database::dontRequireTable()
Database::endSchemaUpdate()
Database::fieldList()
Database::getConnect()
Database::getGeneratedID()
Database::isActive()
Database::manipulate()
Database::query()
Database::quiet()
Database::renameTable()
Database::replace_with_null()
Database::requireField()
Database::requireIndex()
Database::requireTable()
Database::tableList()
Database::transAlterField()
Database::transAlterIndex()
Database::transCreateField()
Database::transCreateIndex()
Database::transCreateTable()
Database::transInitTable()

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::hasExtension()
Object::hasMethod()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Sun, 19 Oct 2008 06:44:17 +1300 by phpDocumentor 1.3.2