Database

Database access object factory. Normally the database configs and object names are defined in the app config array or ini file, "$object-name = Database::get('object-name');" will return the database access object on demand. A database connection and object creation is done on the first demand, the object and connection will remain alive for the next demands.
Source
Database.php
Implements
IObjectFactory
Depends on
Arta , DatabaseErrorEngineNotSupported , IDbAdvanced

Static Methods

config

array|string Database::config(
    string objectName=null,
    string index=null,
    array configs=null
)

Set or get configs for a database access object. The configs will only be set if a last param is passed. The configs are stored in "Arta::$dbConfigs" which also contains the app database object configs (from the app config ini file or array).

Arguments

    objectName=null (string)
    The object name to set or to get configs for, null=return all object configs
    index=null (string)
    Config key, to get the value of a specific setting
    configs=null (array)
    To add a new database connection/object configs
    {
        string engine   : database engine name e.g. PostgreSQL, MySQL,
        string server   : localhost database server address,
        string port     : depends on the engine database server port,
        string dbname   : database name,
        string user     : database user-name,
        string password : database password,
        string advanced : false
            false=create an IDbAbstract instance
            true=create an IDbAdvanced instance,
    }
    

Returns

array|string
{configs} or {object-name: {configs},} or the value of a config key

get

IDbAbstract|IDbAdvanced|array Database::get(
    string | bool objectName=null,
    bool remove=false
)

Creates and returns or returns an already created object. When creating a new object the connection/object configs are expected to exists in "Arta::$dbConfigs", note that the database connection/objects defined in the app config array or ini file are put in "Arta::$dbConfigs" by Artaengine.
Get a database access object by passing the object name.
Get all database access objects in an array by passing true.
To remove an object pass true for the second argument.

See also
http://artaengine.com/tutorials/database#connecting

Arguments

    objectName=null (string | bool)
    Object name to create or to get handle of, null=return the last object in the list, true=return all objects
    remove=false (bool)
    true=remove/unsset the object

Returns

IDbAbstract|IDbAdvanced|array
Reference to a database access object or a list of database access objects

Throws

getCreateNew

IDbAbstract|IDbAdvanced Database::getCreateNew(string objectName, array configs)

Creates and returns an object. Use this method to create a new object by passing the connection/object configs versus "get()" that expects the configs to exist in "Arta::$dbConfigs".

Arguments

    objectName (string)
    The object name to be created
    configs (array)
    Database connection/object configs
    {
        string engine   : database engine name e.g. PostgreSQL, MySQL,
        string server   : localhost database server address,
        string port     : depends on the engine database server port,
        string dbname   : database name,
        string user     : database user-name,
        string password : database password,
        string advanced : false
            false=create an IDbAbstract instance
            true=create an IDbAdvanced instance,
    }
    

Returns

IDbAbstract|IDbAdvanced
Reference to the newly created database access object

Throws

remove

void Database::remove(string objectName)

Remove an object if already been created.

Arguments

    objectName (string)
    Object name to remove

Returns

void

upgrade

IDbAdvanced Database::upgrade(IDbAbstract | string objectName='dbo')

Converts an abstract database access object into an advanced database access object and returns it. An advanced (IDbAdvanced) database access object is an extend to an abstract database access object (IDbAbstract) which adds methods for extra actions such as create and alter table.

See also
http://artaengine.com/tutorials/database#advanced

Arguments

    objectName='dbo' (IDbAbstract | string)
    Name of the database access object or the object itself

Returns

IDbAdvanced
Database advanced object