Rev 1231 | Rev 1316 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1231 | Rev 1241 | ||
---|---|---|---|
Line 141... | Line 141... | ||
141 | 141 | ||
142 | try { |
142 | try { |
143 | $options = [ |
143 | $options = [ |
144 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_SILENT, |
144 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_SILENT, |
145 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, |
145 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, |
146 | \PDO::ATTR_EMULATE_PREPARES => true, |
146 | \PDO::ATTR_EMULATE_PREPARES => true |
147 | ]; |
147 | ]; |
148 | 148 | ||
149 | // Try connecting to the database |
149 | // Try connecting to the database |
150 | $dsn = OIDplus::baseConfig()->getValue('PDO_DSN', 'mysql:host=localhost;dbname=oidplus;charset=utf8mb4'); |
150 | $dsn = OIDplus::baseConfig()->getValue('PDO_DSN', 'mysql:host=localhost;dbname=oidplus;charset=utf8mb4'); |
151 | $username = OIDplus::baseConfig()->getValue('PDO_USERNAME', (str_starts_with($dsn,'odbc:')) ? '' : 'root'); |
151 | $username = OIDplus::baseConfig()->getValue('PDO_USERNAME', (str_starts_with($dsn,'odbc:')) ? '' : 'root'); |
Line 191... | Line 191... | ||
191 | try { |
191 | try { |
192 | @$this->conn->exec("SET NAMES 'utf8mb4'"); |
192 | @$this->conn->exec("SET NAMES 'utf8mb4'"); |
193 | } catch (\Exception $e) { |
193 | } catch (\Exception $e) { |
194 | } |
194 | } |
195 | 195 | ||
- | 196 | $this->detectTransactionSupport(); |
|
- | 197 | } |
|
- | 198 | ||
- | 199 | /** |
|
- | 200 | * @return void |
|
- | 201 | */ |
|
196 | // We check if the DBMS supports autocommit. |
202 | private function detectTransactionSupport() { |
- | 203 | try { |
|
197 | // Attention: Check it after you have sent a query already, because Microsoft Access doesn't seem to allow |
204 | // Attention: Check it after you have already sent a query, because Microsoft Access doesn't seem to allow |
198 | // changing auto commit once a query was executed ("Attribute cannot be set now SQLState: S1011") |
205 | // changing auto commit once a query was executed ("Attribute cannot be set now SQLState: S1011") |
199 | // Note: For some weird reason we *DO* need to redirect the output to "$dummy", otherwise it won't work! |
206 | // Note: For some weird reason we *DO* need to redirect the output to "$dummy", otherwise it won't work! |
200 | $sql = "select name from ###config where 1=0"; |
207 | $sql = "select name from ###config where 1=0"; |
201 | $sql = str_replace('###', OIDplus::baseConfig()->getValue('TABLENAME_PREFIX', ''), $sql); |
208 | $sql = str_replace('###', OIDplus::baseConfig()->getValue('TABLENAME_PREFIX', ''), $sql); |
202 | $dummy = $this->conn->query($sql); |
209 | $dummy = $this->conn->query($sql); |
- | 210 | } catch (\Exception $e) { |
|
- | 211 | // Microsoft Access might output that "xyz_config" is not found, if TABLENAME_PREFIX is wrong |
|
- | 212 | // We didn't had the change to verify the existance of ###config using afterConnectMandatory() at this stage. |
|
- | 213 | // This try-catch is usually not required because our error mode is set to silent. |
|
- | 214 | } |
|
- | 215 | ||
- | 216 | // Note for Firebird: If Firebird uses auto-transactions via PDO, it doesn't allow an explicit transaction after a query has been |
|
- | 217 | // executed once in auto-commit mode. For some reason, the query was auto-committed, but after the auto-comit, a new transaction is |
|
- | 218 | // automatically opened, so new explicit transaction are denied with the error messag ethat a transaction is still open. A bug?! |
|
- | 219 | // If we explicit commit the implicitly opened transaction, we can use explicit transactions, but once |
|
- | 220 | // we want to run a normal query, Firebird denies it, saying that no transaction is open (because it asserts that an implicit |
|
- | 221 | // opened transaction is available). |
|
- | 222 | // The only solution would be to disable auto-commit and do everything ourselves, but this is a complex and risky task, |
|
- | 223 | // so we just let Firebird run in Transaction-Disabled-Mode. |
|
- | 224 | ||
203 | try { |
225 | try { |
204 | $this->conn->beginTransaction(); |
226 | if (!$this->conn->beginTransaction()) { |
- | 227 | $this->transactions_supported = false; |
|
- | 228 | } else { |
|
205 | $this->conn->rollBack(); |
229 | $this->conn->rollBack(); |
206 | $this->transactions_supported = true; |
230 | $this->transactions_supported = true; |
- | 231 | } |
|
207 | } catch (\Exception $e) { |
232 | } catch (\Exception $e) { |
208 | $this->transactions_supported = false; |
233 | $this->transactions_supported = false; |
209 | } |
234 | } |
210 | } |
235 | } |
211 | 236 | ||
212 | /** |
237 | /** |
213 | * @return void |
238 | * @return void |
214 | */ |
239 | */ |
215 | protected function doDisconnect()/*: void*/ { |
240 | protected function doDisconnect()/*: void*/ { |
- | 241 | /* |
|
- | 242 | if (!$this->conn->getAttribute(\PDO::ATTR_AUTOCOMMIT)) { |
|
- | 243 | try { |
|
- | 244 | $this->conn->commit(); |
|
- | 245 | } catch (\Exception $e) { |
|
- | 246 | } |
|
- | 247 | } |
|
- | 248 | */ |
|
216 | $this->conn = null; // the connection will be closed by removing the reference |
249 | $this->conn = null; // the connection will be closed by removing the reference |
217 | } |
250 | } |
218 | 251 | ||
219 | /** |
252 | /** |
220 | * @var bool |
253 | * @var bool |