-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #899 from LuckyCyborg/master
Introduce in the Database API the support for using PostgresSQL and SQLite Databases
- Loading branch information
Showing
8 changed files
with
440 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* Connector - A PDO based Database Connector. | ||
* | ||
* @author Virgil-Adrian Teaca - virgil@giulianaeassociati.com | ||
* @version 3.0 | ||
*/ | ||
|
||
namespace Database\Connectors; | ||
|
||
use PDO; | ||
|
||
|
||
abstract class Connector | ||
{ | ||
/** | ||
* The default PDO connection options. | ||
* | ||
* @var array | ||
*/ | ||
protected $options = array( | ||
PDO::ATTR_CASE => PDO::CASE_NATURAL, | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, | ||
PDO::ATTR_STRINGIFY_FETCHES => false, | ||
PDO::ATTR_EMULATE_PREPARES => false, | ||
); | ||
|
||
/** | ||
* The keyword identifier wrapper format. | ||
* | ||
* @var string | ||
*/ | ||
protected $wrapper = '`%s`'; | ||
|
||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Get the PDO options based on the configuration. | ||
* | ||
* @param array $config | ||
* @return array | ||
*/ | ||
public function getOptions(array $config) | ||
{ | ||
$options = array_get($config, 'options', array()); | ||
|
||
return array_diff_key($this->options, $options) + $options; | ||
} | ||
|
||
/** | ||
* Create a new PDO connection. | ||
* | ||
* @param string $dsn | ||
* @param array $config | ||
* @param array $options | ||
* @return PDO | ||
*/ | ||
public function createConnection($dsn, array $config, array $options) | ||
{ | ||
$username = array_get($config, 'username'); | ||
|
||
$password = array_get($config, 'password'); | ||
|
||
return new PDO($dsn, $username, $password, $options); | ||
} | ||
|
||
/** | ||
* Get the default PDO connection options. | ||
* | ||
* @return array | ||
*/ | ||
public function getDefaultOptions() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* Set the default PDO connection options. | ||
* | ||
* @param array $options | ||
* @return void | ||
*/ | ||
public function setDefaultOptions(array $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Get the keyword identifier wrapper format. | ||
* | ||
* @return string | ||
*/ | ||
public function getWrapper() | ||
{ | ||
return $this->wrapper; | ||
} | ||
|
||
/** | ||
* Get the format for database stored dates. | ||
* | ||
* @return string | ||
*/ | ||
public function getDateFormat() | ||
{ | ||
return 'Y-m-d H:i:s'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Database\Connectors; | ||
|
||
|
||
interface ConnectorInterface | ||
{ | ||
/** | ||
* Establish a database connection. | ||
* | ||
* @param array $config | ||
* @return \PDO | ||
*/ | ||
public function connect(array $config); | ||
|
||
} |
Oops, something went wrong.