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