Permalink
Browse files

Pass settings as assoc array as first arg of new DB();

  • Loading branch information...
1 parent 3fc53be commit 14a36fe90754343204d6e9c2f1351f8d51f0f05f @jasny committed Jan 9, 2013
Showing with 13 additions and 11 deletions.
  1. +1 −1 composer.json
  2. +12 −10 src/Jasny/MySQL/DB.php
View
2 composer.json
@@ -2,7 +2,7 @@
"name": "jasny/db-mysql",
"description": "A simple DB layer in PHP for using MySQL",
"keywords": ["database", "db", "mysql"],
- "version": "v1.1.0",
+ "version": "v1.1.1",
"license": "MIT",
"homepage": "http://jasny.github.com/DB-MySQL",
"authors": [
View
22 src/Jasny/MySQL/DB.php
@@ -51,9 +51,7 @@ public static function conn()
// Auto connect using Jasny's Config class
if (!isset(self::$connection)) {
if (!class_exists('Jasny\Config') || !isset(\Jasny\Config::i()->db)) throw new DB_Exception("Unable to create DB connection: not configured");
-
- $cfg = \Jasny\Config::i()->db;
- new static(isset($cfg->host) ? $cfg->host : 'localhost', $cfg->username, $cfg->password, isset($cfg->dbname) ? $cfg->dbname : null, isset($cfg->port) ? $cfg->port : null);
+ new static(\Jasny\Config::i()->db);
}
return self::$connection;
@@ -62,15 +60,19 @@ public static function conn()
/**
* Class constructor.
*
- * @param string $host MySQL hostname
- * @param string $username MySQL username
- * @param string $passwd User's password
- * @param string $dbname Database name
- * @param int $port MySQL port
+ * @param string|array $host Hostname or settings as assoc array
+ * @param string $username
+ * @param string $password
+ * @param string $dbname
+ * @param int $port
*/
- public function __construct($host, $username, $passwd, $dbname, $port = null)
+ public function __construct($host, $username = null, $password = null, $dbname = null, $port = null)
{
- parent::__construct($host, $username, $passwd, $dbname, $port);
+ if (!is_scalar($host)) {
+ extract((array)$host, EXTR_IF_EXISTS);
+ }
+
+ parent::__construct($host, $username, $password, $dbname, $port);
$this->set_charset('utf8');
if (!isset(self::$connection)) self::$connection = $this;

0 comments on commit 14a36fe

Please sign in to comment.