Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / lib / Doctrine / DBAL / Driver / IBMDB2 / DB2Connection.php
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 MIT license. For more information, see
19  * <http://www.doctrine-project.org>.
20 */
21
22 namespace Doctrine\DBAL\Driver\IBMDB2;
23
24 class DB2Connection implements \Doctrine\DBAL\Driver\Connection
25 {
26     private $_conn = null;
27
28     public function __construct(array $params, $username, $password, $driverOptions = array())
29     {
30         $isPersistant = (isset($params['persistent']) && $params['persistent'] == true);
31
32         if ($isPersistant) {
33             $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
34         } else {
35             $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
36         }
37         if ( ! $this->_conn) {
38             throw new DB2Exception(db2_conn_errormsg());
39         }
40     }
41
42     public function prepare($sql)
43     {
44         $stmt = @db2_prepare($this->_conn, $sql);
45         if ( ! $stmt) {
46             throw new DB2Exception(db2_stmt_errormsg());
47         }
48         return new DB2Statement($stmt);
49     }
50
51     public function query()
52     {
53         $args = func_get_args();
54         $sql = $args[0];
55         $stmt = $this->prepare($sql);
56         $stmt->execute();
57         return $stmt;
58     }
59
60     public function quote($input, $type=\PDO::PARAM_STR)
61     {
62         $input = db2_escape_string($input);
63         if ($type == \PDO::PARAM_INT ) {
64             return $input;
65         } else {
66             return "'".$input."'";
67         }
68     }
69
70     public function exec($statement)
71     {
72         $stmt = $this->prepare($statement);
73         $stmt->execute();
74         return $stmt->rowCount();
75     }
76
77     public function lastInsertId($name = null)
78     {
79         return db2_last_insert_id($this->_conn);
80     }
81
82     public function beginTransaction()
83     {
84         db2_autocommit($this->_conn, DB2_AUTOCOMMIT_OFF);
85     }
86
87     public function commit()
88     {
89         if (!db2_commit($this->_conn)) {
90             throw new DB2Exception(db2_conn_errormsg($this->_conn));
91         }
92         db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
93     }
94
95     public function rollBack()
96     {
97         if (!db2_rollback($this->_conn)) {
98             throw new DB2Exception(db2_conn_errormsg($this->_conn));
99         }
100         db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
101     }
102
103     public function errorCode()
104     {
105         return db2_conn_error($this->_conn);
106     }
107
108     public function errorInfo()
109     {
110         return array(
111             0 => db2_conn_errormsg($this->_conn),
112             1 => $this->errorCode(),
113         );
114     }
115 }