summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/db.inc
blob: 2de3acce68b00abe8072b430be24768dae6e626e (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?

//	$DB_TYPE	="POSTGRESQL";
	$DB_TYPE	="MYSQL";
	$DB_SERVER	="localhost";
	$DB_DATABASE	="zabbix";
//	$DB_USER	="zabbix";
	$DB_USER	="root";
	$DB_PASSWORD	="";

	$USER_DETAILS	="";

	if($DB_TYPE == "MYSQL")
	{
		$DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD);
		mysql_select_db($DB_DATABASE);
	}
	if($DB_TYPE == "POSTGRESQL")
	{
		$DB=pg_pconnect("host=$DB_SERVER dbname=$DB_DATABASE user=$DB_USER password=$DB_PASSWORD");
		if(!$DB)
		{
			echo "Error connecting to database";
			exit;
		}
	}

	function	DBselect($query)
	{
		global $DB,$DB_TYPE;

//		echo $query,"<br>";

		if($DB_TYPE == "MYSQL")
		{
			$result=mysql_query($query,$DB);
			return $result;
		}
		if($DB_TYPE == "POSTGRESQL")
		{
			$result=pg_exec($DB,$query);
			return $result;
		}
	}

	function	DBexecute($query)
	{
		global $DB,$DB_TYPE;

//		echo $query,"<br>";

		if($DB_TYPE == "MYSQL")
		{
			$result=mysql_query($query,$DB);
			return $result;
		}
		if($DB_TYPE == "POSTGRESQL")
		{
			$result=pg_exec($DB,$query);
			return $result;
		}
	}

	function	DBfetch($result)
	{
		global $DB_TYPE;

		if($DB_TYPE == "MYSQL")
		{
			$row=mysql_fetch_array($result);
			return $row;
		}
		if($DB_TYPE == "POSTGRESQL")
		{
			$row=pg_fetch_array($result);
			return $row;
		}
	}

	function	DBget_field($result,$rownum,$fieldnum)
	{
		global $DB_TYPE;

		if($DB_TYPE == "MYSQL")
		{
			mysql_data_seek($result,$rownum);
			$row=mysql_fetch_row($result);
			return $row[$fieldnum];
		}
		if($DB_TYPE == "POSTGRESQL")
		{
			$row=pg_fetch_row($result,$rownum);
			if(!$row)
			{
				echo "Error getting row";
				exit;
			}
			return $row[$fieldnum];
		}
	}

	function	DBnum_rows($result)
	{
		global $DB_TYPE;
	
		if($DB_TYPE == "MYSQL")
		{
			return mysql_num_rows($result);
		}
		if($DB_TYPE == "POSTGRESQL")
		{
			return pg_numrows($result);
		}
	}

	function	DBinsert_id($result,$table,$field)
	{
		global	$DB,$DB_TYPE;

		if($DB_TYPE == "MYSQL")
		{
			return mysql_insert_id($DB);
		}

		if($DB_TYPE == "POSTGRESQL")
		{
			$oid=pg_getlastoid($result);
//			echo "OID:$oid<br>";
			$sql="select $field from $table where oid=$oid";
			$result=DBselect($sql);
			return DBget_field($result,0,0);
		}
	}

?>