mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 10:36:16 +00:00
Removing silent errors in PDO dbo's when a connection exception is created.
Adding the host param for mysql. Adding a test for mysql missing the host param. Fixes #1427
This commit is contained in:
parent
d3d009588d
commit
de6eda964e
4 changed files with 19 additions and 6 deletions
|
@ -148,14 +148,14 @@ class DboMysql extends DboSource {
|
|||
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
|
||||
}
|
||||
$this->_connection = new PDO(
|
||||
"mysql:{$config['host']};port={$config['port']};dbname={$config['database']}",
|
||||
"mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
|
||||
$config['login'],
|
||||
$config['password'],
|
||||
$flags
|
||||
);
|
||||
$this->connected = true;
|
||||
} catch (PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
|
||||
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
|
||||
|
|
|
@ -130,7 +130,7 @@ class DboPostgres extends DboSource {
|
|||
$this->_execute('SET search_path TO ' . $config['schema']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
|
||||
return $this->connected;
|
||||
|
|
|
@ -114,9 +114,8 @@ class DboSqlite extends DboSource {
|
|||
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
|
||||
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->connected = true;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
} catch(PDOException $e) {
|
||||
throw new MissingConnectionException(array('class' => $e->getMessage()));
|
||||
}
|
||||
return $this->connected;
|
||||
}
|
||||
|
|
|
@ -3367,4 +3367,18 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$this->assertTrue(Set::matches('/Comment[id=2]', $result));
|
||||
$this->assertFalse(Set::matches('/Comment[id=10]', $result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException MissingConnectionException
|
||||
* @return void
|
||||
*/
|
||||
function testExceptionOnBrokenConnection() {
|
||||
$dbo = new DboMysql(array(
|
||||
'driver' => 'mysql',
|
||||
'host' => 'imaginary_host',
|
||||
'login' => 'mark',
|
||||
'password' => 'inyurdatabase',
|
||||
'database' => 'imaginary'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue