diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 98e2cf5d2..1cdb1ddc1 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -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", ">="); diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 540ec0944..b6106d87b 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -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; diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index c09b175e2..ae5c25f11 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -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; } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 5ddce2069..ff462f86e 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -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' + )); + } }