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