Permalink
Browse files

Refactored building dsn string. Now works with PGSQL.

  • Loading branch information...
1 parent 99fc0cb commit 1e06f66192929c81b0e5dd0adcd324ad140f4890 @bauffman bauffman committed Feb 6, 2012
Showing with 16 additions and 6 deletions.
  1. +16 −6 library/spoon/database/database.php
@@ -132,23 +132,33 @@ private function connect()
{
try
{
- // build dsn
- if($this->port !== null) $dsn = $this->driver . ':host=' . $this->hostname . ';port=' . $this->port . ';dbname=' . $this->database;
- else $dsn = $this->driver . ':host=' . $this->hostname . ';dbname=' . $this->database;
+ $dsn = $this->driver;
+ $dsn .= ':host=' . $this->hostname;
+ $dsn .= ';dbname=' . $this->database;
+ $dsn .= ';user=' . $this->username;
+ $dsn .= ';password=' . $this->password;
+
+ if($this->port !== null)
+ {
+ $dsn .= ';port=' . $this->port;
+ }
// create handler
$this->handler = new PDO($dsn, $this->username, $this->password);
$this->handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+ // mysql only option
+ if($this->driver == 'mysql')
+ {
+ $this->handler->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+ }
}
catch(PDOException $e)
{
throw new SpoonDatabaseException('A database connection could not be established.', 0, $this->password);
}
}
-
- // set nasty option
- $this->handler->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}

0 comments on commit 1e06f66

Please sign in to comment.