mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-28 04:32:57 +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
lib/Cake/Model/Datasource/Database
|
@ -136,20 +136,24 @@ class Mysql extends DboSource {
|
||||||
public function connect() {
|
public function connect() {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
try {
|
|
||||||
$flags = array(
|
$flags = array(
|
||||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($config['encoding'])) {
|
if (!empty($config['encoding'])) {
|
||||||
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($config['unix_socket'])) {
|
if (empty($config['unix_socket'])) {
|
||||||
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
|
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
|
||||||
} else {
|
} else {
|
||||||
$dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
|
$dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$this->_connection = new PDO(
|
$this->_connection = new PDO(
|
||||||
$dsn,
|
$dsn,
|
||||||
$config['login'],
|
$config['login'],
|
||||||
|
|
|
@ -110,11 +110,13 @@ class Postgres extends DboSource {
|
||||||
public function connect() {
|
public function connect() {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
try {
|
|
||||||
$flags = array(
|
$flags = array(
|
||||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
$this->_connection = new PDO(
|
$this->_connection = new PDO(
|
||||||
"pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
|
"pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
|
||||||
$config['login'],
|
$config['login'],
|
||||||
|
|
|
@ -117,14 +117,17 @@ class Sqlserver extends DboSource {
|
||||||
public function connect() {
|
public function connect() {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
try {
|
|
||||||
$flags = array(
|
$flags = array(
|
||||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($config['encoding'])) {
|
if (!empty($config['encoding'])) {
|
||||||
$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
|
$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$this->_connection = new PDO(
|
$this->_connection = new PDO(
|
||||||
"sqlsrv:server={$config['host']};Database={$config['database']}",
|
"sqlsrv:server={$config['host']};Database={$config['database']}",
|
||||||
$config['login'],
|
$config['login'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue