20 lines
445 B
PHP
20 lines
445 B
PHP
<?php
|
|
/**
|
|
* Common utilities for new API services.
|
|
*/
|
|
|
|
/**
|
|
* Establishes a database connection and returns the connection resource.
|
|
* Dies on failure.
|
|
*
|
|
* @return resource
|
|
*/
|
|
function get_db_connection() {
|
|
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws");
|
|
if ($dbconn === false) {
|
|
http_response_code(500);
|
|
die('Database connection failed: ' . pg_last_error());
|
|
}
|
|
return $dbconn;
|
|
}
|
|
?>
|