Bouncy Melons 0.2
declarative style orm
Driver.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm;
4 
5 class Driver {
6 
7  protected $pdo;
8 
9  public function __construct(\PDO $pdo) {
10  $this->pdo = $pdo;
11  }
12 
13  public function getPDO() {
14  return $this->pdo;
15  }
16 
17  public function exec($query) {
18  $statement = $this->getPDO()->query($query);
19  if(false === $statement) {
20  list($errno, $errint, $msg) = $this->getPDO()->errorInfo();
21 // var_dump($query);
22  throw new EExec($msg, $errint);
23  }
24  $statement = null;
25  }
26 
33  public function query($sql) {
34  $re = $this->getPDO()->query($sql);
35  if($re === false) {
36  list($errno, $errint, $msg) = $this->getPDO()->errorInfo();
37  throw new ESelect($msg, $errint);
38  }
39  $data = $re->fetchAll(\PDO::FETCH_ASSOC);
40  $re = null;
41  return $data;
42  }
43 
50  public function queryOne($sql) {
51  $data = $this->query($sql);
52  if(empty($data)) {
53  throw new EItemNotFound();
54  }
55  return reset($data);
56  }
57 
63  public function queryParam($sql) {
64  $data = $this->queryOne($sql);
65  return reset($data);
66  }
67 }
queryParam($sql)
Definition: Driver.php:63
queryOne($sql)
Definition: Driver.php:50
__construct(\PDO $pdo)
Definition: Driver.php:9
query($sql)
Definition: Driver.php:33
getPDO()
Definition: Driver.php:13
exec($query)
Definition: Driver.php:17