Skip to content

Commit 57a97eb

Browse files
author
romanb
committed
[2.0][DDC-120] First version of OCI8 driver.
1 parent 8e3f6ee commit 57a97eb

File tree

3 files changed

+427
-0
lines changed

3 files changed

+427
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+
*
17+
* This software consists of voluntary contributions made by many individuals
18+
* and is licensed under the LGPL. For more information, see
19+
* <http://www.doctrine-project.org>.
20+
*/
21+
22+
namespace Doctrine\DBAL\Driver\OCI8;
23+
24+
use Doctrine\DBAL\Platforms;
25+
26+
/**
27+
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
28+
*
29+
* @author Roman Borschel <roman@code-factory.org>
30+
* @since 2.0
31+
*/
32+
class Driver implements \Doctrine\DBAL\Driver
33+
{
34+
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
35+
{
36+
return new OCI8Connection(
37+
$username,
38+
$password,
39+
$this->_constructDsn($params)
40+
);
41+
}
42+
43+
/**
44+
* Constructs the Oracle DSN.
45+
*
46+
* @return string The DSN.
47+
*/
48+
private function _constructDsn(array $params)
49+
{
50+
$dsn = '';
51+
if (isset($params['host'])) {
52+
$dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
53+
'(HOST=' . $params['host'] . ')';
54+
55+
if (isset($params['port'])) {
56+
$dsn .= '(PORT=' . $params['port'] . ')';
57+
} else {
58+
$dsn .= '(PORT=1521)';
59+
}
60+
61+
$dsn .= '))(CONNECT_DATA=(SID=' . $params['dbname'] . ')))';
62+
} else {
63+
$dsn .= $params['dbname'];
64+
}
65+
66+
if (isset($params['charset'])) {
67+
$dsn .= ';charset=' . $params['charset'];
68+
}
69+
70+
return $dsn;
71+
}
72+
73+
public function getDatabasePlatform()
74+
{
75+
return new \Doctrine\DBAL\Platforms\OraclePlatform();
76+
}
77+
78+
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
79+
{
80+
return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
81+
}
82+
83+
public function getName()
84+
{
85+
return 'oci8';
86+
}
87+
88+
public function getDatabase(\Doctrine\DBAL\Connection $conn)
89+
{
90+
$params = $conn->getParams();
91+
return $params['user'];
92+
}
93+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+
*
17+
* This software consists of voluntary contributions made by many individuals
18+
* and is licensed under the LGPL. For more information, see
19+
* <http://www.doctrine-project.org>.
20+
*/
21+
22+
namespace Doctrine\DBAL\Driver\OCI8;
23+
24+
/**
25+
* OCI8 implementation of the Connection interface.
26+
*
27+
* @since 2.0
28+
*/
29+
class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
30+
{
31+
private $_dbh;
32+
33+
public function __construct($username, $password, $db)
34+
{
35+
$this->_dbh = oci_connect($username, $password, $db);
36+
}
37+
38+
public function prepare($prepareString)
39+
{
40+
return new OCI8Statement($this->_dbh, $prepareString);
41+
}
42+
43+
public function query()
44+
{
45+
$args = func_get_args();
46+
$sql = $args[0];
47+
//$fetchMode = $args[1];
48+
$stmt = $this->prepare($sql);
49+
$stmt->execute();
50+
return $stmt;
51+
}
52+
53+
public function quote($input)
54+
{
55+
return is_numeric($input) ? $input : "'$input'";
56+
}
57+
58+
public function exec($statement)
59+
{
60+
$stmt = $this->prepare($statement);
61+
$stmt->execute();
62+
return $stmt->rowCount();
63+
}
64+
65+
public function lastInsertId($name = null)
66+
{
67+
//TODO: throw exception or support sequences?
68+
}
69+
70+
public function beginTransaction()
71+
{
72+
return true;
73+
}
74+
75+
public function commit()
76+
{
77+
return oci_commit($this->_dbh);
78+
}
79+
80+
public function rollBack()
81+
{
82+
return oci_rollback($this->_dbh);
83+
}
84+
85+
public function errorCode()
86+
{
87+
$error = oci_error($this->_dbh);
88+
if ($error !== false) {
89+
$error = $error['code'];
90+
}
91+
return $error;
92+
}
93+
94+
public function errorInfo()
95+
{
96+
return oci_error($this->_dbh);
97+
}
98+
99+
}

0 commit comments

Comments
 (0)