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 48... | Line 48... | ||
48 | } |
48 | } |
49 | } |
49 | } |
50 | return OIDplusQueryResultODBC(@odbc_exec($this->conn, $sql)); |
50 | return OIDplusQueryResultODBC(@odbc_exec($this->conn, $sql)); |
51 | */ |
51 | */ |
52 | if (!is_array($prepared_args)) { |
52 | if (!is_array($prepared_args)) { |
53 | throw new OIDplusException("'prepared_args' must be either NULL or an ARRAY."); |
53 | throw new OIDplusException(_L('"prepared_args" must be either NULL or an ARRAY.')); |
54 | } |
54 | } |
55 | 55 | ||
56 | foreach ($prepared_args as &$value) { |
56 | foreach ($prepared_args as &$value) { |
57 | // ODBC/SQLServer has problems converting "true" to the data type "bit" |
57 | // ODBC/SQLServer has problems converting "true" to the data type "bit" |
58 | // Error "Invalid character value for cast specification" |
58 | // Error "Invalid character value for cast specification" |
Line 60... | Line 60... | ||
60 | } |
60 | } |
61 | 61 | ||
62 | $ps = @odbc_prepare($this->conn, $sql); |
62 | $ps = @odbc_prepare($this->conn, $sql); |
63 | if (!$ps) { |
63 | if (!$ps) { |
64 | $this->last_error = odbc_errormsg($this->conn); |
64 | $this->last_error = odbc_errormsg($this->conn); |
65 | throw new OIDplusSQLException($sql, 'Cannot prepare statement: '.$this->error()); |
65 | throw new OIDplusSQLException($sql, _L('Cannot prepare statement').': '.$this->error()); |
66 | } |
66 | } |
67 | 67 | ||
68 | if (!@odbc_execute($ps, $prepared_args)) { |
68 | if (!@odbc_execute($ps, $prepared_args)) { |
69 | $this->last_error = odbc_errormsg($this->conn); |
69 | $this->last_error = odbc_errormsg($this->conn); |
70 | throw new OIDplusSQLException($sql, $this->error()); |
70 | throw new OIDplusSQLException($sql, $this->error()); |
Line 78... | Line 78... | ||
78 | if ($err == null) $err = ''; |
78 | if ($err == null) $err = ''; |
79 | return $err; |
79 | return $err; |
80 | } |
80 | } |
81 | 81 | ||
82 | protected function doConnect()/*: void*/ { |
82 | protected function doConnect()/*: void*/ { |
83 | if (!function_exists('odbc_connect')) throw new OIDplusConfigInitializationException('PHP extension "ODBC" not installed'); |
83 | if (!function_exists('odbc_connect')) throw new OIDplusConfigInitializationException(_L('PHP extension "%1" not installed','ODBC')); |
84 | 84 | ||
85 | // Try connecting to the database |
85 | // Try connecting to the database |
86 | $dsn = OIDplus::baseConfig()->getValue('ODBC_DSN', 'DRIVER={SQL Server};SERVER=localhost;DATABASE=oidplus;CHARSET=UTF8'); |
86 | $dsn = OIDplus::baseConfig()->getValue('ODBC_DSN', 'DRIVER={SQL Server};SERVER=localhost;DATABASE=oidplus;CHARSET=UTF8'); |
87 | $username = OIDplus::baseConfig()->getValue('ODBC_USERNAME', ''); |
87 | $username = OIDplus::baseConfig()->getValue('ODBC_USERNAME', ''); |
88 | $password = OIDplus::baseConfig()->getValue('ODBC_PASSWORD', ''); |
88 | $password = OIDplus::baseConfig()->getValue('ODBC_PASSWORD', ''); |
89 | $this->conn = @odbc_connect($dsn, $username, $password); |
89 | $this->conn = @odbc_connect($dsn, $username, $password); |
90 | 90 | ||
91 | if (!$this->conn) { |
91 | if (!$this->conn) { |
92 | $message = odbc_errormsg(); |
92 | $message = odbc_errormsg(); |
93 | throw new OIDplusConfigInitializationException('Connection to the database failed! '.$message); |
93 | throw new OIDplusConfigInitializationException(_L('Connection to the database failed!').' '.$message); |
94 | } |
94 | } |
95 | 95 | ||
96 | $this->last_error = null; |
96 | $this->last_error = null; |
97 | 97 | ||
98 | try { |
98 | try { |
Line 117... | Line 117... | ||
117 | public function transaction_level(): int { |
117 | public function transaction_level(): int { |
118 | return $this->intransaction ? 1 : 0; |
118 | return $this->intransaction ? 1 : 0; |
119 | } |
119 | } |
120 | 120 | ||
121 | public function transaction_begin()/*: void*/ { |
121 | public function transaction_begin()/*: void*/ { |
122 | if ($this->intransaction) throw new OIDplusException("Nested transactions are not supported by this database plugin."); |
122 | if ($this->intransaction) throw new OIDplusException(_L('Nested transactions are not supported by this database plugin.')); |
123 | odbc_autocommit($this->conn, false); // begin transaction |
123 | odbc_autocommit($this->conn, false); // begin transaction |
124 | $this->intransaction = true; |
124 | $this->intransaction = true; |
125 | } |
125 | } |
126 | 126 | ||
127 | public function transaction_commit()/*: void*/ { |
127 | public function transaction_commit()/*: void*/ { |