Skip to content

Commit 6116502

Browse files
authored
Merge pull request #315 from bomjfedosei/master
Add OracleDB Connector
2 parents 1309668 + c7f86d8 commit 6116502

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace TeamTNT\TNTSearch\Connectors;
4+
5+
use PDO;
6+
7+
class OracleDBConnector extends Connector implements ConnectorInterface {
8+
9+
/**
10+
* The PDO connection options.
11+
*
12+
* @var array
13+
*/
14+
protected $options = array(
15+
PDO::ATTR_CASE => PDO::CASE_NATURAL,
16+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
17+
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
18+
PDO::ATTR_STRINGIFY_FETCHES => false,
19+
);
20+
21+
/**
22+
* Establish a database connection.
23+
*
24+
* @param array $config
25+
* @return PDO
26+
*/
27+
public function connect(array $config)
28+
{
29+
$options = $this->getOptions($config);
30+
31+
return $this->createConnection($this->getDsn($config), $config, $options);
32+
}
33+
34+
/**
35+
* Create a DSN string from a configuration.
36+
*
37+
* @param array $config
38+
* @return string
39+
*/
40+
protected function getDsn(array $config)
41+
{
42+
extract($config);
43+
44+
// First we will create the basic DSN setup as well as the port if it is in
45+
// in the configuration options. This will give us the basic DSN we will
46+
// need to establish the PDO connections and return them back for use.
47+
48+
if (in_array('oci', $this->getAvailableDrivers()))
49+
{
50+
return "oci:dbname={$dbtns};charset=utf8";
51+
}
52+
}
53+
54+
/**
55+
* Get the available PDO drivers.
56+
*
57+
* @return array
58+
*/
59+
protected function getAvailableDrivers()
60+
{
61+
return PDO::getAvailableDrivers();
62+
}
63+
64+
}

src/Engines/EngineTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function createConnector(array $config)
4343
return new SqlServerConnector;
4444
case 'filesystem':
4545
return new FileSystemConnector;
46+
case 'oracledb':
47+
return new OracleDBConnector;
4648
}
4749
throw new Exception("Unsupported driver [{$config['driver']}]");
4850
}

0 commit comments

Comments
 (0)