From 6f1f5eed0dde057b84da4b3230666e68f3beab04 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Jun 2011 22:30:41 -0500 Subject: [PATCH] allow literal path in sqlite database config. --- system/db/connector.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/system/db/connector.php b/system/db/connector.php index d5aab6d1..249bc48b 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -22,16 +22,29 @@ class Connector { */ public static function connect($config) { - // --------------------------------------------------- - // Establish a SQLite PDO connection. - // --------------------------------------------------- + // ----------------------------------------------------- + // Connect to SQLite. + // ----------------------------------------------------- if ($config->driver == 'sqlite') { - return new \PDO('sqlite:'.APP_PATH.'db/'.$config->database.'.sqlite', null, null, static::$options); + // ----------------------------------------------------- + // Check the application/db directory first. + // ----------------------------------------------------- + if (file_exists($path = APP_PATH.'db/'.$config->database.'.sqlite')) + { + return new \PDO('sqlite:'.$path, null, null, static::$options); + } + // ----------------------------------------------------- + // Is the database name the full path? + // ----------------------------------------------------- + elseif (file_exists($config->database)) + { + return new \PDO('sqlite:'.$config->database, null, null, static::$options); + } } - // --------------------------------------------------- - // Establish a MySQL or Postgres PDO connection. - // --------------------------------------------------- + // ----------------------------------------------------- + // Connect to MySQL or Postgres. + // ----------------------------------------------------- elseif ($config->driver == 'mysql' or $config->driver == 'pgsql') { $connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options); @@ -43,10 +56,8 @@ public static function connect($config) return $connection; } - else - { - throw new \Exception('Database driver '.$config->driver.' is not supported.'); - } + + throw new \Exception('Database driver '.$config->driver.' is not supported.'); } } \ No newline at end of file