postgres.php 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php namespace Laravel\Database\Connectors; use PDO;
  2. class Postgres extends Connector {
  3. /**
  4. * Establish a PDO database connection.
  5. *
  6. * @param array $config
  7. * @return PDO
  8. */
  9. public function connect($config)
  10. {
  11. extract($config);
  12. $dsn = "pgsql:host={$host};dbname={$database}";
  13. // The developer has the freedom of specifying a port for the PostgresSQL
  14. // database or the default port (5432) will be used by PDO to create the
  15. // connection to the database for the developer.
  16. if (isset($config['port']))
  17. {
  18. $dsn .= ";port={$config['port']}";
  19. }
  20. $connection = new PDO($dsn, $username, $password, $this->options($config));
  21. // If a character set has been specified, we'll execute a query against
  22. // the database to set the correct character set. By default, this is
  23. // set to UTF-8 which should be fine for most scenarios.
  24. if (isset($config['charset']))
  25. {
  26. $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
  27. }
  28. return $connection;
  29. }
  30. }