summaryrefslogtreecommitdiff
path: root/src/test/pdo-test/mod/database.inc
blob: 6f4a1e45945aa1008d07f8f6ade4eb4ea4e94ccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36


<?php
require_once('def.inc');
	function dbconnect() {
		try { 
			$string ="pgsql:host=".HOSTNAME.";port=".PORT.";dbname=".DBNAME;
			$dbh = NULL;
			$dbh = new PDO($string,USER,PASS);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);;
			return $dbh;
		} catch (Exception $e) {
			echo "fail : " .$e->getMessage()." <BR>";
			ErrorResult($php_errormsg);
			return NULL;
		}
	}

	function trans_end($dbh,$trans) {
		try { 
			$stmt = $dbh->prepare($trans);
			$stmt->execute();
			print_r($stmt->fetch());
		} catch (Exception $e) {
			ErrorResult($php_errormsg);
		}
	}

	function ErrorResult($php_errormsg) {
		header('HTTP/1.0 402 SQL ERROR');
		require_once("errorhandler.inc");
		set_error_handler("userErrorHandler");
		trigger_error($php_errormsg, E_USER_ERROR);
		exit;
	}
?>