| 1 |
<?php
|
| 2 |
// $Id:$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Submits a query, creates connection if not present.
|
| 6 |
* @return result of pg_query() or FALSE;
|
| 7 |
*/
|
| 8 |
function db_pg_query($query) {
|
| 9 |
static $conn;
|
| 10 |
if (!$conn) {
|
| 11 |
if (!$db_pg_url = variable_get('db_pg_url', FALSE)) {
|
| 12 |
drupal_set_message('Could not connect to PGSQL DB. Missing connection string $conf[\'db_pg_url\']', 'error');
|
| 13 |
return FALSE;
|
| 14 |
}
|
| 15 |
if (!$conn = pg_connect($db_pg_url)) {
|
| 16 |
drupal_set_message('Could not connect to PGSQL DB. '. pg_last_error(), 'error');
|
| 17 |
return FALSE;
|
| 18 |
}
|
| 19 |
}
|
| 20 |
if ($result = pg_query($conn, $query)) {
|
| 21 |
return $result;
|
| 22 |
}
|
| 23 |
drupal_set_message(pg_last_error($conn), 'error');
|
| 24 |
}
|