Package DE_EPAGES::Database::API::Connection
This package provides an interface to make, get and close connections.
@EXPORT_OK |
Functions
- Connect
- ConnectSite
- ConnectTestSite
- ConnectToSite
- DisconnectSite
- EncryptDBPassword
- GetCurrentDBHandle
- GetTestSite
- RunOnStore
- SetCurrentDBHandle
- Transaction
Connect
Connects to any database via the connection string (defined at DBI). Username and password are required. The correct DBI interface will be selected to make connection. Use SetCurrentDBHandle to make the database handle accessible from DAL functions.
Syntax |
my $dbh = Connect($DataSource, $Login, $Password, $CacheKey) |
Example |
my $dbh = Connect('dbi:mysql:admindb', 'admin', 'geheim', 'admindb') |
Input |
|
Return |
|
ConnectSite
Connects to any database with config file Database.d/$Store.conf. The password is not required if it is defined in the config file. Throws an error if the connection is not active. This function sets the current database handle to make the database handle accessable from DAL functions.
Syntax |
ConnectSite($Store); ConnectSite($Store, $Password); |
Example |
ConnectSite('Site'); |
Input |
|
ConnectTestSite
Connects to the test database (see GetTestSite). The password must be set in Database.d/$TestSite.conf.
Syntax |
ConnectTestSite(); |
Input |
|
ConnectToSite
Connects to site database (section [Site.Default] at Database.d/Site.conf). The password is not required if it is set in the config file.
Syntax |
ConnectToSite(); ConnectToSite($Password); |
Input |
|
DisconnectSite
Disconnect current site connection and reset global current database handle site alias.
Syntax |
DisconnectSite(); |
EncryptDBPassword
Crypt the plain password to save it at Database.d/$Store.conf. Enter the crypted password at the Database.d/$Store.conf so that passwords are hidden for users which have file system access.
Syntax |
$EncPassword = EncryptDBPassword($Password); |
Input |
|
Return |
|
GetCurrentDBHandle
Returns the current database handle.
Syntax |
$dbh = GetCurrentDBHandle(); |
Return |
|
GetTestSite
Returns the connection name of the test database. The name can be specified by the EPAGES_TESTSITE environment variable. The default value is 'Site'.
Syntax |
my $StoreName = GetTestSite(); |
Example |
RunOnStore( 'Store'=> GetTestSite(), 'Sub' => sub { print LoadRootObject()->get('StoreName'); }); |
Input |
|
RunOnStore
Runs the main function in the context of the Error module and enables detailed error information.
Syntax |
RunOnStore( %Options ); |
Example |
RunOnStore( 'Store'=> $Store, 'DBPassword'=> $DBPassword, 'Sub' => $Sub, ); |
Input |
|
SetCurrentDBHandle
Sets the current database handle.
Syntax |
SetCurrentDBHandle($dbh); |
Input |
|
Transaction
Runs a code block in a transaction using the current database handle. In this transaction is no cache reset involved.
Syntax |
Transaction( $cCode, $cRollback); |
Example |
Transaction( sub { ProcessSql( ... ); ProcessSql( ... ); } ); |
Input |
|