Development

/branches/1.3/lib/database/sfPostgreSQLDatabase.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/database/sfPostgreSQLDatabase.class.php

Revision 23810, 2.6 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfPostgreSQLDatabase provides connectivity for the PostgreSQL brand database.
14  *
15  * <b>Optional parameters:</b>
16  *
17  * # <b>database</b>   - [none]      - The database name.
18  * # <b>host</b>       - [localhost] - The database host.
19  * # <b>username</b>   - [none]      - The database username.
20  * # <b>password</b>   - [none]      - The database password.
21  * # <b>persistent</b> - [No]        - Indicates that the connection should be persistent.
22  * # <b>port</b>       - [none]      - TCP/IP port on which PostgreSQL is listening.
23  *
24  * @package    symfony
25  * @subpackage database
26  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
27  * @author     Sean Kerr <sean@code-box.org>
28  * @version    SVN: $Id$
29  */
30 class sfPostgreSQLDatabase extends sfDatabase
31 {
32   /**
33    * Connects to the database.
34    *
35    * @throws <b>sfDatabaseException</b> If a connection could not be created
36    */
37   public function connect()
38   {
39     $database = $this->getParameter('database');
40     $host     = $this->getParameter('host');
41     $password = $this->getParameter('password');
42     $port     = $this->getParameter('port');
43     $username = $this->getParameter('username');
44
45     // construct connection string
46     $string = ($database != null ? (' dbname='   .$database) : '').
47               ($host != null     ? (' host='     .$host)     : '').
48               ($password != null ? (' password=' .$password) : '').
49               ($port != null     ? (' port='     .$port)     : '').
50               ($username != null ? (' user='     .$username) : '');
51
52     // let's see if we need a persistent connection
53     $persistent = $this->getParameter('persistent', false);
54     $connect    = $persistent ? 'pg_pconnect' : 'pg_connect';
55
56     $this->connection = @$connect($string);
57
58     // make sure the connection went through
59     if ($this->connection === false)
60     {
61       // the connection's foobar'd
62       throw new sfDatabaseException('Failed to create a PostgreSQLDatabase connection.');
63     }
64
65     // since we're not an abstraction layer, we copy the connection
66     // to the resource
67     $this->resource = $this->connection;
68   }
69
70   /**
71    * Executes the shutdown procedure.
72    *
73    * @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database
74    */
75   public function shutdown()
76   {
77     if ($this->connection != null)
78     {
79       @pg_close($this->connection);
80     }
81   }
82 }
83
Note: See TracBrowser for help on using the browser.