In debug, output the sql queries in italic. Refer to enabling debugging in the FAQ
[freeradius.git] / dialup_admin / lib / sql / drivers / pg / functions.php3
1 <?php
2 function da_sql_connect($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=$config[sql_server] port=$config[sql_port]
14                         dbname=$config[sql_database] user=$SQL_user
15                         password=$SQL_passwd");
16 }
17
18 function da_sql_pconnect($config)
19 {
20         return @pg_pconnect("host=$config[sql_server] port=$config[sql_port]
21                         dbname=$config[sql_database] user=$config[sql_username]
22                         password=$config[sql_password]");
23 }
24
25 function da_sql_close($link,$config)
26 {
27         @pg_close($link);
28 }
29
30 function da_sql_query($link,$config,$query)
31 {
32         if ($config[sql_debug] == 'true')
33                 print "<b>DEBUG(SQL,PG DRIVER): Query: <i>$query</i></b><br>\n";
34         return @pg_exec($link,$query);
35 }
36
37 function da_sql_num_rows($result,$config)
38 {
39         if ($config[sql_debug] == 'true')
40                 print "<b>DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . @pg_numrows($result) . "</b><br>\n";
41         return @pg_numrows($result);
42 }
43
44 function da_sql_fetch_array($result,$config)
45 {
46         if ($config[sql_debug] == 'true'){
47                 print "<b>DEBUG(SQL,PG DRIVER): Query Result: ";
48                 print_r(@pg_fetch_array($result,$config[tmp_pg_array_num][$result]++,PGSQL_ASSOC));
49                 print  "</b><br>\n";
50         }
51         $row = @pg_fetch_array($result,$config[tmp_pg_array_num][$result]++,PGSQL_ASSOC);
52         if (!$row)
53                 $config[tmp_pg_array_num][$result] = 0;
54         return $row;
55 }
56
57 function da_sql_affected_rows($link,$result,$config)
58 {
59         if ($config[sql_debug] == 'true')
60                 print "<b>DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result) . "</b><br>\n";
61         return @pg_cmdtuples($result);
62 }
63
64 function da_sql_list_fields($table,$link,$config)
65 {
66         $res = @pg_exec($link,
67                 "select count(*) from pg_attribute where attnum > '0' and
68                 attrelid = (select oid from pg_class where relname='$table');");
69         if ($res){
70                 $row = @pg_fetch_row($res,0);
71                 if ($row){
72                         if (!$row[0])
73                                 return NULL;
74                         $fields[num] = $row[0];
75                 }
76         }
77         $res = @pg_exec($link,
78                 "select attname from pg_attribute where attnum > '0' and
79                 attrelid = (select oid from pg_class where relname='$table');");
80         if ($res)
81                 $fields[res]=$res;
82         else
83                 return NULL;
84
85         return $fields;
86 }
87
88 function da_sql_num_fields($fields,$config)
89 {
90         if ($fields)
91                 return $fields[num];
92 }
93
94 function da_sql_field_name($fields,$num,$config)
95 {
96         if ($fields){
97                 $row = @pg_fetch_row($fields[res],$num);        
98                 if ($row)
99                         return $row[0];
100         }
101 }
102
103 function da_sql_error($link,$config)
104 {
105         return pg_errormessage($link);
106 }
107 ?>