Packagephi.db
Classpublic class Database
ImplementsIDatabase

A Singleton IDatabase implementation.

A Database object assumes these responsibilities:

See also

phi.db.Query


Public Properties
 PropertyDefined by
  connection : ConnectionData
[write-only]
Database
Public Methods
 MethodDefined by
  
Constructor.
Database
  
connect(name:String, user:String, pass:String, host:String, db:String, bDefault:Boolean = false):void
Create a new connection with a remote application server.
Database
  
disconnect(name:String):void
Disconnect from a previous connection
Database
  
getConnections():Number
Get the number of current open connections.
Database
  
Get the default connection name
Database
  
[static] Database Singleton Factory method.
Database
  
retrieveConnection(connectionName:String):ConnectionData
Retrieve an connection information.
Database
  
setDefaultConnection(name:String):void
Set a connection as a default
Database
Property detail
connectionproperty
connection:ConnectionData  [write-only]Implementation
    public function set connection(value:ConnectionData):void
Constructor detail
Database()constructor
public function Database()

Constructor.

This IDatabase implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method Database.getInstance()


Throws
— Error if Singleton instance has already been constructed
Method detail
connect()method
public function connect(name:String, user:String, pass:String, host:String, db:String, bDefault:Boolean = false):void

Create a new connection with a remote application server. This connection can be use for execute SQL statements to a database.
More then one connection can be made but you must enter at least one connection for the Database object to work.

Parameters
name:String — the name of the connection
 
user:String — the username of the remote application server
 
pass:String — the password of the remote application server
 
host:String — the server ip
 
db:String — the database name
 
bDefault:Boolean (default = false) — set this connection as a default connection

Throws
— Error if a connection with the same name allready exist.

Example
The following code create 2 connections:
   var db:IDatabase = Database.getInstance();
   
   db.connect("conn1", "pop", "poppass", "localhost", "yb20");
   db.connect("conn2", "pop", "poppass", "localhost", "test_db");
   

disconnect()method 
public function disconnect(name:String):void

Disconnect from a previous connection

Parameters
name:String — the name of the connection

Throws
— Error if the connection don't exist.
getConnections()method 
public function getConnections():Number

Get the number of current open connections.

Returns
Number — the number of current open connections.
getDefaultConnectionName()method 
public function getDefaultConnectionName():String

Get the default connection name

Returns
String — a string with the name of the default connection
getInstance()method 
public static function getInstance():IDatabase

Database Singleton Factory method.

Returns
IDatabase — the Singleton instance of Database
retrieveConnection()method 
public function retrieveConnection(connectionName:String):ConnectionData

Retrieve an connection information.

Parameters
connectionName:String — the name of the connection to retrieve.

Returns
ConnectionData — an ConnectionData instance previously created with the connect function.

Throws
— Error if the connection don't exist.
setDefaultConnection()method 
public function setDefaultConnection(name:String):void

Set a connection as a default

Parameters
name:String — the connection name