-
-
Notifications
You must be signed in to change notification settings - Fork 292
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 #315 from bomjfedosei/master
Add OracleDB Connector
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace TeamTNT\TNTSearch\Connectors; | ||
|
||
use PDO; | ||
|
||
class OracleDBConnector extends Connector implements ConnectorInterface { | ||
|
||
/** | ||
* The 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, | ||
); | ||
|
||
/** | ||
* Establish a database connection. | ||
* | ||
* @param array $config | ||
* @return PDO | ||
*/ | ||
public function connect(array $config) | ||
{ | ||
$options = $this->getOptions($config); | ||
|
||
return $this->createConnection($this->getDsn($config), $config, $options); | ||
} | ||
|
||
/** | ||
* Create a DSN string from a configuration. | ||
* | ||
* @param array $config | ||
* @return string | ||
*/ | ||
protected function getDsn(array $config) | ||
{ | ||
extract($config); | ||
|
||
// First we will create the basic DSN setup as well as the port if it is in | ||
// in the configuration options. This will give us the basic DSN we will | ||
// need to establish the PDO connections and return them back for use. | ||
|
||
if (in_array('oci', $this->getAvailableDrivers())) | ||
{ | ||
return "oci:dbname={$dbtns};charset=utf8"; | ||
} | ||
} | ||
|
||
/** | ||
* Get the available PDO drivers. | ||
* | ||
* @return array | ||
*/ | ||
protected function getAvailableDrivers() | ||
{ | ||
return PDO::getAvailableDrivers(); | ||
} | ||
|
||
} |
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