nyroFwk  0.2
db/pdo/abstract.class.php
Go to the documentation of this file.
1 <?php
10 abstract class db_pdo_abstract extends db_abstract {
11 
17  protected $connection;
18 
22  protected function _connect() {
23  if ($this->connection)
24  return;
25 
26  $this->connection = new PDO(
27  $this->_dsn(),
28  $this->cfg->user,
29  $this->cfg->pass,
30  $this->cfg->driverOptions);
31 
32  foreach($this->cfg->conQuery as $q)
33  $this->connection->query($q);
34 
35  $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
36  }
37 
43  protected function _dsn() {
44  return $this->cfg->driver.':host='.$this->cfg->host.';dbname='.$this->cfg->base;
45  }
46 
52  public function closeConnection() {
53  $this->connection = null;
54  }
55 
63  public function prepare($sql, array $options=array()) {
64  $this->_connect();
65  return $this->connection->prepare($sql, $options);
66  }
67 
73  public function lastInsertId() {
74  $this->_connect();
75  return $this->connection->lastInsertId();
76  }
77 
81  protected function _beginTransaction() {
82  $this->_connect();
83  $this->connection->beginTransaction();
84  }
85 
89  protected function _commit() {
90  $this->_connect();
91  $this->connection->commit();
92  }
93 
97  protected function _rollBack() {
98  $this->_connect();
99  $this->connection->rollBack();
100  }
101 
102 }
prepare($sql, array $options=array())
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13