6 * @returns (PDO) - reference to PDO object
7 * @returns (boolean) false, if there is no connection to the database
9 * if there is a connection to the database,
10 * the PDO object is returned otherwise false
18 $objDB = getDBDataObject();
20 return $objDB->get('PDO');
25 * @returns (boolean) true, if connection exists or is established
26 * @returns (boolean) false, if connection could not be established
28 * if no connection to the database exists, establishe one.
36 $objDB = getDBDataObject();
39 $objPDO = new \PDO($objDB->get('CONNECTION'),
42 } catch (\Exception $objException) {
46 $objDB->update(array('PDO' => $objPDO));
53 * disconnect from the database
56 function disconnect() {
58 $objDB = getDBDataObject();
60 $objPDO = $objDB->get('PDO');
63 $objDB->delete('PDO');
68 * check if a connection to the database is established
71 function isConnected() {
73 $objDB = getDBDataObject();
75 if(!$objDB->exists('PDO'))
83 * @returns (boolean) true, if transaction started
84 * @returns (boolean) false, if transaction could not be started
85 * @returns (boolean) false, if no connection to database exists
90 function startTransaction() {
92 return mapMethod('beginTransaction');
97 * @returns (boolean) true, if there is an active transaction
98 * @returns (boolean) false, if there is no active transaction
99 * @returns (boolean) false, if no connection to database exists
101 * check if there is an active transaction
104 function inTransaction() {
106 return mapMethod('inTransaction');
111 * @returns (boolean) true, if rollback was successfull
112 * @returns (boolean) false, if rollback was not successfull
113 * @returns (boolean) false, if no connection to database exists
115 * perform a rollback of the active transaction
118 function rollback() {
120 return mapMethod('rollback');
125 * @returns (boolean) true, if commit was successfull
126 * @returns (boolean) false, if commit was not successfull
127 * @returns (boolean) false, if no connection to database exists
129 * commit the active transaction
134 return mapMethod('commit');
139 * @returns (array) - list of error-information
141 * get information about an error
144 function getErrorInfo() {
146 return mapMethod('errorInfo');
151 * change the active database-connection. all db-functions
152 * are performed at the new connection.
154 * ATTENTION: the old connection is *not* closed!
157 function changeDB($strIdentifier) {
159 $objDataObjectPool = new DataObjectPool('Database-Definition');
161 $objNewDB = $objDataObjectPool->get($strIdentifier);
163 $objDataObjectPool->delete('DEFAULT');
164 $objDataObjectPool->add('DEFAULT', $objNewDB->getAll());
170 * @returns (DataObject) - reference to the DataObject of default connection
172 * returns the DataObject of the default connection.
175 function getDBDataObject() {
177 $objDataObjectPool = new DataObjectPool('Database-Definition');
178 return $objDataObjectPool->get('DEFAULT');
183 * @throws UnexpectedParameterTypeException - if the given parameter is not a string
185 * @returns (boolean) false, if no connection is established
187 * check if a connection to the database is established. if so,
188 * the given parameter is used, as method to call at the
189 * PDO object. the result of the call is returned
192 function mapMethod($strMethod) {
194 if(!is_string($strMethod))
195 throw new UnexpectedParameterTypeException('string', $strMethod);
200 $objDB = getDBDataObject();
202 $objPDO = $objDB->get('PDO');
204 return $objPDO->$strMethod();