Subversion Repositories oidplus

Rev

Rev 348 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 348 Rev 360
Line 49... Line 49...
49
                        }
49
                        }
50
                        return OIDplusQueryResultPDO($this->conn->query($sql));
50
                        return OIDplusQueryResultPDO($this->conn->query($sql));
51
                        */
51
                        */
52
 
52
 
53
                        if (!is_array($prepared_args)) {
53
                        if (!is_array($prepared_args)) {
54
                                throw new OIDplusException("'prepared_args' must be either NULL or an ARRAY.");
54
                                throw new OIDplusException(_L('"prepared_args" must be either NULL or an ARRAY.'));
55
                        }
55
                        }
56
 
56
 
57
                        foreach ($prepared_args as &$value) {
57
                        foreach ($prepared_args as &$value) {
58
                                // We need to manually convert booleans into strings, because there is a
58
                                // We need to manually convert booleans into strings, because there is a
59
                                // 14 year old bug that hasn't been adressed by the PDO developers:
59
                                // 14 year old bug that hasn't been adressed by the PDO developers:
Line 63... Line 63...
63
                        }
63
                        }
64
 
64
 
65
                        $ps = $this->conn->prepare($sql);
65
                        $ps = $this->conn->prepare($sql);
66
                        if (!$ps) {
66
                        if (!$ps) {
67
                                $this->last_error = $ps->errorInfo()[2];
67
                                $this->last_error = $ps->errorInfo()[2];
68
                                throw new OIDplusSQLException($sql, 'Cannot prepare statement: '.$this->error());
68
                                throw new OIDplusSQLException($sql, _L('Cannot prepare statement').': '.$this->error());
69
                        }
69
                        }
70
                        $this->prepare_cache[$sql] = $ps;
70
                        $this->prepare_cache[$sql] = $ps;
71
 
71
 
72
                        if (!$ps->execute($prepared_args)) {
72
                        if (!$ps->execute($prepared_args)) {
73
                                $this->last_error = $ps->errorInfo()[2];
73
                                $this->last_error = $ps->errorInfo()[2];
Line 86... Line 86...
86
                if ($err == null) $err = '';
86
                if ($err == null) $err = '';
87
                return $err;
87
                return $err;
88
        }
88
        }
89
 
89
 
90
        protected function doConnect()/*: void*/ {
90
        protected function doConnect()/*: void*/ {
91
                if (!class_exists('PDO')) throw new OIDplusConfigInitializationException('PHP extension "PDO" not installed');
91
                if (!class_exists('PDO')) throw new OIDplusConfigInitializationException(_L('PHP extension "%1" not installed','PDO'));
92
 
92
 
93
                try {
93
                try {
94
                        $options = [
94
                        $options = [
95
                            PDO::ATTR_ERRMODE            => PDO::ERRMODE_SILENT,
95
                            PDO::ATTR_ERRMODE            => PDO::ERRMODE_SILENT,
96
                            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
96
                            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
Line 102... Line 102...
102
                        $username = OIDplus::baseConfig()->getValue('PDO_USERNAME', 'root');
102
                        $username = OIDplus::baseConfig()->getValue('PDO_USERNAME', 'root');
103
                        $password = OIDplus::baseConfig()->getValue('PDO_PASSWORD', '');
103
                        $password = OIDplus::baseConfig()->getValue('PDO_PASSWORD', '');
104
                        $this->conn = new PDO($dsn, $username, $password, $options);
104
                        $this->conn = new PDO($dsn, $username, $password, $options);
105
                } catch (PDOException $e) {
105
                } catch (PDOException $e) {
106
                        $message = $e->getMessage();
106
                        $message = $e->getMessage();
107
                        throw new OIDplusConfigInitializationException('Connection to the database failed! '.$message);
107
                        throw new OIDplusConfigInitializationException(_L('Connection to the database failed!').' '.$message);
108
                }
108
                }
109
 
109
 
110
                $this->last_error = null;
110
                $this->last_error = null;
111
 
111
 
112
                $this->query("SET NAMES 'utf8'");
112
                $this->query("SET NAMES 'utf8'");
Line 125... Line 125...
125
        public function transaction_level(): int {
125
        public function transaction_level(): int {
126
                return $this->intransaction ? 1 : 0;
126
                return $this->intransaction ? 1 : 0;
127
        }
127
        }
128
 
128
 
129
        public function transaction_begin()/*: void*/ {
129
        public function transaction_begin()/*: void*/ {
130
                if ($this->intransaction) throw new OIDplusException("Nested transactions are not supported by this database plugin.");
130
                if ($this->intransaction) throw new OIDplusException(_L('Nested transactions are not supported by this database plugin.'));
131
                $this->conn->beginTransaction();
131
                $this->conn->beginTransaction();
132
                $this->intransaction = true;
132
                $this->intransaction = true;
133
        }
133
        }
134
 
134
 
135
        public function transaction_commit()/*: void*/ {
135
        public function transaction_commit()/*: void*/ {