mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Moves code out of the try/catch blocks in the connect() methods.
That code wouldn't throw a PDOException, so having it in the try/catch block is pointless. Moving it out makes it easier to read.
This commit is contained in:
parent
c7e4076770
commit
1fe424a62b
3 changed files with 33 additions and 24 deletions
|
@ -136,20 +136,24 @@ class Mysql extends DboSource {
|
|||
public function connect() {
|
||||
$config = $this->config;
|
||||
$this->connected = false;
|
||||
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
if (!empty($config['encoding'])) {
|
||||
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
||||
}
|
||||
|
||||
if (empty($config['unix_socket'])) {
|
||||
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
|
||||
} else {
|
||||
$dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
|
||||
}
|
||||
|
||||
try {
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
if (!empty($config['encoding'])) {
|
||||
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
||||
}
|
||||
if (empty($config['unix_socket'])) {
|
||||
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
|
||||
} else {
|
||||
$dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
|
||||
}
|
||||
$this->_connection = new PDO(
|
||||
$dsn,
|
||||
$config['login'],
|
||||
|
|
|
@ -110,11 +110,13 @@ class Postgres extends DboSource {
|
|||
public function connect() {
|
||||
$config = $this->config;
|
||||
$this->connected = false;
|
||||
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
try {
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
$this->_connection = new PDO(
|
||||
"pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
|
||||
$config['login'],
|
||||
|
|
|
@ -117,14 +117,17 @@ class Sqlserver extends DboSource {
|
|||
public function connect() {
|
||||
$config = $this->config;
|
||||
$this->connected = false;
|
||||
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
if (!empty($config['encoding'])) {
|
||||
$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
|
||||
}
|
||||
|
||||
try {
|
||||
$flags = array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
if (!empty($config['encoding'])) {
|
||||
$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
|
||||
}
|
||||
$this->_connection = new PDO(
|
||||
"sqlsrv:server={$config['host']};Database={$config['database']}",
|
||||
$config['login'],
|
||||
|
|
Loading…
Add table
Reference in a new issue