Commit: baf5052e4b9ea7d57591b70e21478be4b33313c1

Author: Nate Abele | Date: 2010-03-08 08:27:21 -0500
Modifying default configuration for `\data\source\Database` so that no default database is specified. Updating `MySql` adapter so that a connection is not attempted without a valid configuration.
diff --git a/libraries/lithium/data/source/Database.php b/libraries/lithium/data/source/Database.php index 85c442f..84e7bb6 100644 --- a/libraries/lithium/data/source/Database.php +++ b/libraries/lithium/data/source/Database.php @@ -100,7 +100,7 @@ abstract class Database extends \lithium\data\Source { * - 'login' _string_ Username to use when connecting to server. Defaults to 'root'. * - 'password' _string_ Password to use when connecting to server. Defaults to none. * - 'persistent' _boolean_ If true a persistent connection will be attempted, provided the - * adapter supports it. Defaults to true. + * adapter supports it. Defaults to `true`. * * @param $config array Array of configuration options. * @return Database object. @@ -111,9 +111,9 @@ abstract class Database extends \lithium\data\Source { 'host' => 'localhost', 'login' => 'root', 'password' => '', - 'database' => 'lithium', + 'database' => null, ); - parent::__construct((array) $config + $defaults); + parent::__construct($config + $defaults); } /** diff --git a/libraries/lithium/data/source/database/adapter/MySql.php b/libraries/lithium/data/source/database/adapter/MySql.php index 97dd592..039d0a8 100644 --- a/libraries/lithium/data/source/database/adapter/MySql.php +++ b/libraries/lithium/data/source/database/adapter/MySql.php @@ -68,13 +68,18 @@ class MySql extends \lithium\data\source\Database { /** * Connects to the database using the options provided to the class constructor. * - * @return boolean True if the database could be connected, else false. + * @return boolean Returns `true` if a database connection could be established, otherwise + * `false`. */ public function connect() { $config = $this->_config; $this->_isConnected = false; $host = $config['host'] . ':' . $config['port']; + if (!$config['database']) { + return false; + } + if ($config['persistent']) { $this->_connection = mysql_connect($host, $config['login'], $config['password'], true); } else { diff --git a/libraries/lithium/tests/cases/data/source/DatabaseTest.php b/libraries/lithium/tests/cases/data/source/DatabaseTest.php index 53b5bbc..8a28414 100644 --- a/libraries/lithium/tests/cases/data/source/DatabaseTest.php +++ b/libraries/lithium/tests/cases/data/source/DatabaseTest.php @@ -31,7 +31,7 @@ class DatabaseTest extends \lithium\test\Unit { 'host' => 'localhost', 'login' => 'root', 'password' => '', - 'database' => 'lithium', + 'database' => null, 'autoConnect' => true, 'init' => true ); @@ -46,7 +46,7 @@ class DatabaseTest extends \lithium\test\Unit { 'host' => '127.0.0.1', 'login' => 'bob', 'password' => '', - 'database' => 'lithium', + 'database' => null, 'autoConnect' => true, 'init' => true );