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.
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>.
22 namespace Doctrine\DBAL\Driver\IBMDB2;
24 class DB2Connection implements \Doctrine\DBAL\Driver\Connection
26 private $_conn = null;
28 public function __construct(array $params, $username, $password, $driverOptions = array())
30 $isPersistant = (isset($params['persistent']) && $params['persistent'] == true);
33 $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
35 $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
37 if ( ! $this->_conn) {
38 throw new DB2Exception(db2_conn_errormsg());
42 public function prepare($sql)
44 $stmt = @db2_prepare($this->_conn, $sql);
46 throw new DB2Exception(db2_stmt_errormsg());
48 return new DB2Statement($stmt);
51 public function query()
53 $args = func_get_args();
55 $stmt = $this->prepare($sql);
60 public function quote($input, $type=\PDO::PARAM_STR)
62 $input = db2_escape_string($input);
63 if ($type == \PDO::PARAM_INT ) {
66 return "'".$input."'";
70 public function exec($statement)
72 $stmt = $this->prepare($statement);
74 return $stmt->rowCount();
77 public function lastInsertId($name = null)
79 return db2_last_insert_id($this->_conn);
82 public function beginTransaction()
84 db2_autocommit($this->_conn, DB2_AUTOCOMMIT_OFF);
87 public function commit()
89 if (!db2_commit($this->_conn)) {
90 throw new DB2Exception(db2_conn_errormsg($this->_conn));
92 db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
95 public function rollBack()
97 if (!db2_rollback($this->_conn)) {
98 throw new DB2Exception(db2_conn_errormsg($this->_conn));
100 db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
103 public function errorCode()
105 return db2_conn_error($this->_conn);
108 public function errorInfo()
111 0 => db2_conn_errormsg($this->_conn),
112 1 => $this->errorCode(),