Class TDataSourceConfig

Description

TDataSourceConfig module class provides <module> configuration for database connections.

Example usage: mysql connection

  1. <modules>
  2. <module id="db1">
  3. <database ConnectionString="mysqli:host=localhost;dbname=test"
  4. username="dbuser" password="dbpass" />
  5. </module>
  6. </modules>

Usage in php:

  1. class Home extends TPage
  2. {
  3. function onLoad($param)
  4. {
  5. $db = $this->Application->Modules['db1']->DbConnection;
  6. $db->createCommand('...'); //...
  7. }
  8. }

The properties of <connection> are those of the class TDbConnection. Set setConnectionClass attribute for a custom database connection class that extends the TDbConnection class.

  • since: 3.1
  • version: $Id: TDataSourceConfig.php 2390 2008-03-07 16:13:12Z xue $
  • author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/TDataSourceConfig.php (line 49)

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TDataSourceConfig
Direct descendents
Class Description
TActiveRecordConfig TActiveRecordConfig module configuration class.
TSqlMapConfig TSqlMapConfig module configuration class.
Method Summary
void getConnectionClass (string 0)
string getConnectionID ()
void init (TXmlDocument $xml)
void setConnectionClass (string $value)
void setConnectionID (string $value)
Methods
findConnectionByID (line 145)

Finds the database connection instance from the Application modules.

  • return: database connection.
  • access: protected
  • throws: TConfigurationException when module is not of TDbConnection or TDataSourceConfig.
TDbConnection findConnectionByID (string $id)
  • string $id: Database connection module ID.
getConnectionClass (line 118)
  • access: public
void getConnectionClass (string 0)
  • string 0: Database connection class name to be created.
getConnectionID (line 83)
  • return: connection module ID.
  • access: public
string getConnectionID ()
getDatabase (line 110)

Alias for getDbConnection().

  • return: database connection.
  • access: public
TDbConnection getDatabase ()
getDbConnection (line 94)

Gets the TDbConnection from another module if setConnectionID is supplied and valid. Otherwise, a connection of type given by setConnectionClass is created.

  • return: database connection.
  • access: public
TDbConnection getDbConnection ()
init (line 59)

Initalize the database connection properties from attributes in <database> tag.

  • access: public
void init (TXmlDocument $xml)

Redefinition of:
TModule::init()
Initializes the module.

Redefined in descendants as:
setConnectionClass (line 132)

The database connection class name to be created when getDbConnection

method is called and ConnectionID is null. The ConnectionClass property must be set before calling getDbConnection if you wish to create the connection using the given class name.

  • access: public
  • throws: TConfigurationException when database connection is already established.
void setConnectionClass (string $value)
  • string $value: Database connection class name.
setConnectionID (line 75)

The module ID of another TDataSourceConfig. The getDbConnection property of this configuration will equal to getDbConnection of the given TDataSourceConfig module.

  • access: public
void setConnectionID (string $value)
  • string $value: module ID.

Inherited Methods

Inherited From TModule

TModule::getID()
TModule::init()
TModule::setID()

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Mon, 21 Apr 2008 11:34:40 -0400 by phpDocumentor 1.3.0RC4