/[drupal]/contributions/modules/bugbits/database.pgsql.inc
ViewVC logotype

Contents of /contributions/modules/bugbits/database.pgsql.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Aug 21 23:19:21 2009 UTC (3 months ago) by daften
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +99 -0 lines
File MIME type: text/x-php
Copied the DRUPAL-6--1 branch to head (merge didn't seem to work)
1 <?php
2 // $Id: database.pgsql.inc,v 1.1.2.3 2009/02/04 01:59:00 daften Exp $
3
4 /**
5 * @file
6 * Mantis database interface code for PostgreSQL database servers.
7 */
8
9 function _bugbits_db_connect($username, $password, $database_name, $host = 'localhost', $port = NULL) {
10 // Check if PostgreSQL support is present in PHP
11 if (!function_exists('pg_connect')) {
12 watchdog("Bugbits", "Unable to use the PostgreSQL database (for Mantis) because the PostgreSQL extension for PHP is not installed. Check your <code>php.ini</code> to see how you can enable it.", array(), WATCHDOG_ERROR);
13 }
14
15 // Decode url-encoded information in the db connection string
16 if (isset($username)) {
17 $conn_string .= ' user='. $username;
18 }
19 if (isset($password)) {
20 $conn_string .= ' password='. urldecode($password);
21 }
22 if (isset($host)) {
23 $conn_string .= ' host='. urldecode($host);
24 }
25 if (isset($database_name)) {
26 $conn_string .= ' dbname='. $database_name;
27 }
28 if (isset($url['port'])) {
29 $conn_string .= ' port='. $port;
30 }
31
32 // pg_last_error() does not return a useful error message for database
33 // connection errors. We must turn on error tracking to get at a good error
34 // message, which will be stored in $php_errormsg.
35 $track_errors_previous = ini_get('track_errors');
36 ini_set('track_errors', 1);
37
38 $connection = @pg_connect($conn_string);
39 if (!$connection) {
40 watchdog("Bugbits", $php_errormsg, array(), WATCHDOG_ERROR);
41 }
42
43 // Restore error tracking setting
44 ini_set('track_errors', $track_errors_previous);
45
46 pg_query($connection, "set client_encoding=\"UTF8\"");
47 return $connection;
48 }
49
50 /**
51 * Runs a basic query in the active database.
52 *
53 * @param $query
54 * A string containing an SQL query.
55 *
56 * @return
57 * A database query result resource, or FALSE if the query was not
58 * executed correctly.
59 */
60 function _bugbits_db_query($query) {
61 $query = _bugbits_db_prefix_tables($query);
62 return pg_query($query);
63 }
64
65 /**
66 * Fetch one result row from the previous query as an object.
67 *
68 * @param $result
69 * A database query result resource, as returned from _bugbits_db_query().
70 * @return
71 * An object representing the next row of the result, or FALSE. The attributes
72 * of this object are the table fields selected by the query.
73 */
74 function _bugbits_db_fetch_object($result) {
75 if ($result) {
76 return pg_fetch_object($result);
77 }
78 }
79
80 /**
81 * Return an individual result field from the previous query.
82 *
83 * Only use this function if exactly one field is being selected; otherwise,
84 * use db_fetch_object() or db_fetch_array().
85 *
86 * @param $result
87 * A database query result resource, as returned from db_query().
88 * @return
89 * The resulting field or FALSE.
90 */
91 function _bugbits_db_result($result) {
92 if ($result && pg_num_rows($result) > 0) {
93 // The mysql_fetch_row function has an optional second parameter $row
94 // but that can't be used for compatibility with Oracle, DB2, etc.
95 $array = pg_fetch_row($result);
96 return $array[0];
97 }
98 return FALSE;
99 }

  ViewVC Help
Powered by ViewVC 1.1.2