Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit bdcc307

Browse files
committed
Updated to version 1.1.3
1 parent abe482c commit bdcc307

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.1.3 - 2017-05-14
4+
* Singleton pattern was added to create a single connection per database.
5+
36
## 1.1.2 - 2017-05-13
47
* Added option for foreign key in creating tables.
58

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "josantonius/database",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"type": "library",
55
"description": "Library for SQL database management to be used by several providers at the same time.",
66
"keywords": [

src/Database.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class Database {
2222
/**
2323
* Identifying name for the database.
2424
*
25-
* @since 1.0.0
25+
* @since 1.1.3
2626
*
2727
* @var object
2828
*/
29-
private static $_databaseID = null;
29+
public static $id = null;
3030

3131
/**
3232
* Database provider.
@@ -234,8 +234,7 @@ class Database {
234234
* @throws DBException → if the provider class specified does not exist
235235
* @throws DBException → if could not connect to provider
236236
*/
237-
private function __construct($provider, $host, $dbUser,
238-
$dbName, $pass, $settings) {
237+
private function __construct($provider, $host, $dbUser, $dbName, $pass, $settings) {
239238

240239
$providerClass = 'Josantonius\\Database\\Provider\\' . $provider;
241240

@@ -278,23 +277,28 @@ private function __construct($provider, $host, $dbUser,
278277
*
279278
* @return object → object with the connection
280279
*/
281-
static function getConnection($databaseID, $provider, $host, $dbUser,
282-
$dbName, $pass, $settings) {
280+
public static function getConnection($databaseID, $provider, $host, $dbUser, $dbName, $pass, $settings) {
283281

284-
if (static::$_databaseID !== $databaseID) {
282+
if (self::$id !== $databaseID) {
285283

286-
static::$_conn = false;
284+
self::$_conn[self::$id] = false;
287285
}
288286

289-
static::$_databaseID = $databaseID;
287+
self::$id = $databaseID;
290288

291-
if (!static::$_conn) {
289+
if (!self::$_conn[self::$id]) {
292290

293-
static::$_conn = new Database($provider, $host, $dbUser,
294-
$dbName, $pass, $settings);
291+
self::$_conn[self::$id] = new Database(
292+
$provider,
293+
$host,
294+
$dbUser,
295+
$dbName,
296+
$pass,
297+
$settings
298+
);
295299
}
296300

297-
return static::$_conn;
301+
return self::$_conn[self::$id];
298302
}
299303

300304
/**

0 commit comments

Comments
 (0)