Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
345 richard 1
<?php
2
function da_sql_limit($limit,$point,$config)
3
{
4
	switch($point){
5
		case 0:
6
			return '';
7
		case 1:
8
			return '';
9
		case 2:
10
			return "LIMIT $limit";
11
	}
12
}
13
function da_sql_host_connect($server,$config)
14
{
15
	if ($config[sql_use_http_credentials] == 'yes'){
16
		global $HTTP_SERVER_VARS;
17
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
18
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
19
	}
20
	else{
21
		$SQL_user = $config[sql_username];
22
		$SQL_passwd = $config[sql_password];
23
	}
24
	if ($config[sql_debug] == 'true')
25
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
26
	return @pg_connect("host=$server port=$config[sql_port]
27
			dbname=$config[sql_database] user=$SQL_user
28
			password=$SQL_passwd");
29
}
30
 
31
function da_sql_connect($config)
32
{
33
	if ($config[sql_use_http_credentials] == 'yes'){
34
		global $HTTP_SERVER_VARS;
35
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
36
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
37
	}
38
	else{
39
		$SQL_user = $config[sql_username];
40
		$SQL_passwd = $config[sql_password];
41
	}
42
	if ($config[sql_debug] == 'true')
43
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
44
	return @pg_connect("host=$config[sql_server] port=$config[sql_port]
45
			dbname=$config[sql_database] user=$SQL_user
46
			password=$SQL_passwd");
47
}
48
 
49
function da_sql_pconnect($config)
50
{
51
	if ($config[sql_use_http_credentials] == 'yes'){
52
		global $HTTP_SERVER_VARS;
53
		$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
54
		$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
55
	}
56
	else{
57
		$SQL_user = $config[sql_username];
58
		$SQL_passwd = $config[sql_password];
59
	}
60
	if ($config[sql_debug] == 'true')
61
		print "<b>DEBUG(SQL,PG DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
62
	return @pg_pconnect("host=$config[sql_server] port=$config[sql_port]
63
			dbname=$config[sql_database] user=$SQL_user
64
			password=$SQL_passwd");
65
}
66
 
67
function da_sql_close($link,$config)
68
{
69
	@pg_close($link);
70
}
71
 
72
function da_sql_escape_string($string)
73
{
74
	return addslashes($string);
75
}
76
 
77
function da_sql_query($link,$config,$query)
78
{
79
	if ($config[sql_debug] == 'true')
80
		print "<b>DEBUG(SQL,PG DRIVER): Query: <i>$query</i></b><br>\n";
81
	return @pg_query($link,$query);
82
}
83
 
84
function da_sql_num_rows($result,$config)
85
{
86
	if ($config[sql_debug] == 'true')
87
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . @pg_numrows($result) . "</b><br>\n";
88
	return @pg_numrows($result);
89
}
90
 
91
function da_sql_fetch_array($result,$config)
92
{
93
	$row = @pg_fetch_array($result,$config[tmp_pg_array_num][$result]++,PGSQL_ASSOC);
94
	if ($row && $config[sql_debug] == 'true'){
95
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: <pre>";
96
		print_r($row);
97
		print  "</b></pre>\n";
98
	}
99
	if (!$row)
100
		$config[tmp_pg_array_num][$result] = 0;
101
	return $row;
102
}
103
 
104
function da_sql_affected_rows($link,$result,$config)
105
{
106
	if ($config[sql_debug] == 'true')
107
		print "<b>DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result) . "</b><br>\n";
108
	return @pg_cmdtuples($result);
109
}
110
 
111
function da_sql_list_fields($table,$link,$config)
112
{
113
	$res = @pg_query($link,
114
		"select count(*) from pg_attribute where attnum > '0' and
115
		attrelid = (select oid from pg_class where relname='$table');");
116
	if ($res){
117
		$row = @pg_fetch_row($res,0);
118
		if ($row){
119
			if (!$row[0])
120
				return NULL;
121
			$fields[num] = $row[0];
122
		}
123
	}
124
	$res = @pg_query($link,
125
		"select attname from pg_attribute where attnum > '0' and
126
		attrelid = (select oid from pg_class where relname='$table');");
127
	if ($res)
128
		$fields[res]=$res;
129
	else
130
		return NULL;
131
 
132
	return $fields;
133
}
134
 
135
function da_sql_num_fields($fields,$config)
136
{
137
	if ($fields)
138
		return $fields[num];
139
}
140
 
141
function da_sql_field_name($fields,$num,$config)
142
{
143
	if ($fields){
144
		$row = @pg_fetch_row($fields[res],$num);
145
		if ($row)
146
			return $row[0];
147
	}
148
}
149
 
150
function da_sql_error($link,$config)
151
{
152
	return pg_errormessage($link);
153
}
154
?>