1. sfPostgreSQLDatabase.class.php
  2. /** * sfPostgreSQLDatabase provides connectivity for the PostgreSQL brand database. * * Optional parameters: * * # database - [none] - The database name. * # host - [localhost] - The database host. * # username - [none] - The database username. * # password - [none] - The database password. * # persistent - [No] - Indicates that the connection should be persistent. * # port - [none] - TCP/IP port on which PostgreSQL is listening. * * @package symfony * @subpackage database * @author Fabien Potencier * @author Sean Kerr * @version SVN: $Id: sfPostgreSQLDatabase.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfPostgreSQLDatabase extends sfDatabase
  4. {
  5. /**
  6. * Connects to the database.
  7. *
  8. * @throws <b>sfDatabaseException</b> If a connection could not be created
  9. */
  10. public function connect()
  11. {
  12. $database = $this->getParameter('database');
  13. $host = $this->getParameter('host');
  14. $password = $this->getParameter('password');
  15. $port = $this->getParameter('port');
  16. $username = $this->getParameter('username');
  17. // construct connection string
  18. $string = ($database != null ? (' dbname=' .$database) : '').
  19. ($host != null ? (' host=' .$host) : '').
  20. ($password != null ? (' password=' .$password) : '').
  21. ($port != null ? (' port=' .$port) : '').
  22. ($username != null ? (' user=' .$username) : '');
  23. // let's see if we need a persistent connection
  24. $persistent = $this->getParameter('persistent', false);
  25. $connect = $persistent ? 'pg_pconnect' : 'pg_connect';
  26. $this->connection = @$connect($string);
  27. // make sure the connection went through
  28. if ($this->connection === false)
  29. {
  30. // the connection's foobar'd
  31. throw new sfDatabaseException('Failed to create a PostgreSQLDatabase connection.');
  32. }
  33. // since we're not an abstraction layer, we copy the connection
  34. // to the resource
  35. $this->resource = $this->connection;
  36. }
  37. /**
  38. * Executes the shutdown procedure.
  39. *
  40. * @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database
  41. */
  42. public function shutdown()
  43. {
  44. if ($this->connection != null)
  45. {
  46. @pg_close($this->connection);
  47. }
  48. }
  49. }

Debug toolbar