Go to the documentation of this file.00001 <?php
00010 abstract class db_pdo_abstract extends db_abstract {
00011
00017 protected $connection;
00018
00022 protected function _connect() {
00023 if ($this->connection)
00024 return;
00025
00026 $this->connection = new PDO(
00027 $this->_dsn(),
00028 $this->cfg->user,
00029 $this->cfg->pass,
00030 $this->cfg->driverOptions);
00031
00032 foreach($this->cfg->conQuery as $q)
00033 $this->connection->query($q);
00034
00035 $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
00036 }
00037
00043 protected function _dsn() {
00044 return $this->cfg->driver.':host='.$this->cfg->host.';dbname='.$this->cfg->base;
00045 }
00046
00052 public function closeConnection() {
00053 $this->connection = null;
00054 }
00055
00063 public function prepare($sql, array $options=array()) {
00064 $this->_connect();
00065 return $this->connection->prepare($sql, $options);
00066 }
00067
00073 public function lastInsertId() {
00074 $this->_connect();
00075 return $this->connection->lastInsertId();
00076 }
00077
00081 protected function _beginTransaction() {
00082 $this->_connect();
00083 $this->connection->beginTransaction();
00084 }
00085
00089 protected function _commit() {
00090 $this->_connect();
00091 $this->connection->commit();
00092 }
00093
00097 protected function _rollBack() {
00098 $this->_connect();
00099 $this->connection->rollBack();
00100 }
00101
00102 }