~gecka/gecka-framework/nautile

« back to all changes in this revision

Viewing changes to Gecka/Database/Pdo.php

  • Committer: Laurent Dinclaux
  • Date: 2008-01-29 23:27:10 UTC
  • Revision ID: laurent@gecka.com-20080129232710-qdypezge2o58relw
First beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require_once 'Gecka/Database/Abstract.php';
 
4
 
 
5
class Gecka_Database_Pdo extends Gecka_Database_Abstract {
 
6
        
 
7
        private $_pdo = null;
 
8
                
 
9
        public function connect() {
 
10
 
 
11
                if($this->_isConnected) return $this;
 
12
                
 
13
                
 
14
                try {
 
15
                        
 
16
                        $this->pdo = new PDO( $this->_type . ':host=' . $this->_host . ';dbname=' . $this->_database . '', $this->_user, $this->_password);
 
17
                
 
18
                } 
 
19
                catch (PDOException $e) {
 
20
                        
 
21
                        throw new Gecka_Database_Exception('Error connecting: ' . $e->getMessage(), $e->getCode() );
 
22
                
 
23
                }
 
24
 
 
25
                $this->_isConnected = true;
 
26
                
 
27
                return $this;
 
28
                
 
29
        }
 
30
        
 
31
        public function query($query) {
 
32
                
 
33
                $this->connect();
 
34
                
 
35
                return $this->_pdo->query($query);
 
36
                
 
37
        }
 
38
        
 
39
        public function exec($query) {
 
40
                
 
41
                $this->connect();
 
42
                
 
43
                return $this->_pdo->exec($query);
 
44
                
 
45
        }
 
46
        
 
47
        public function beginTransaction() {
 
48
                
 
49
                $this->connect();
 
50
                
 
51
                return $this->_pdo->beginTransaction();
 
52
                
 
53
        }
 
54
        
 
55
        public function commit() { 
 
56
                
 
57
                $this->connect();
 
58
                
 
59
                return $this->_pdo->beginTransaction();
 
60
                
 
61
        }
 
62
        
 
63
        public function rollback() {
 
64
                
 
65
                $this->connect();
 
66
                
 
67
                return $this->_pdo->rollback();
 
68
                
 
69
        }
 
70
        
 
71
        public function insert($table, $data) {
 
72
                
 
73
                $query = $this->buildQuery('INSERT', $table, $data);
 
74
                
 
75
                return $this->exec($query);
 
76
                
 
77
        }
 
78
        
 
79
        public function update($table, $data, $condition)  {
 
80
                
 
81
                $query = $this->buildQuery('UPDATE', $table, $data, $condition);
 
82
                
 
83
                return $this->exec($query);
 
84
                
 
85
        }
 
86
        
 
87
        public function replace($table, $data, $condition) {
 
88
                
 
89
                $query = $this->buildQuery('REPLACE', $table, $data, $condition);
 
90
                
 
91
                return $this->exec($query);
 
92
                
 
93
        }
 
94
        
 
95
        public function delete($table, $condition) {
 
96
                
 
97
                $query = $this->buildQuery('DELETE', $table, null, $condition);
 
98
                
 
99
                return $this->exec($query);
 
100
                
 
101
        }
 
102
        
 
103
        public function quote($string) {
 
104
                
 
105
                return $this->_pdo->quote($string);
 
106
                
 
107
        }
 
108
        
 
109
        
 
110
        
 
111
        
 
112
}
 
113
 
 
114
 
 
115
?>
 
 
b'\\ No newline at end of file'