|
| 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 | +} |
0 commit comments