Made it 2.0.0, and removed the changes that are in 1.1.x, as
[freeradius.git] / dialup_admin / lib / sql / drivers / dbx / functions.php3
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
14 function da_sql_host_connect($server,$config)
15 {
16         if ($config[sql_use_http_credentials] == 'yes'){
17                 global $HTTP_SERVER_VARS;
18                 $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
19                 $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
20         }
21         else{
22                 $SQL_user = $config[sql_username];
23                 $SQL_passwd = $config[sql_password];
24         }
25         // FIXME: This function is still Postgres specific. Needs to be configurable.
26         return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
27                         "$SQL_user", "$SQL_passwd", DBX_PERSISTENT);
28 }
29
30 function da_sql_connect($config)
31 {
32         if ($config[sql_use_http_credentials] == 'yes'){
33                 global $HTTP_SERVER_VARS;
34                 $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
35                 $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
36         }
37         else{
38                 $SQL_user = $config[sql_username];
39                 $SQL_passwd = $config[sql_password];
40         }
41         // FIXME: This function is still Postgres specific. Needs to be configurable.
42         return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
43                         "$SQL_user", "$SQL_passwd");
44 }
45
46 function da_sql_pconnect($config)
47 {
48         if ($config[sql_use_http_credentials] == 'yes'){
49                 global $HTTP_SERVER_VARS;
50                 $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
51                 $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
52         }
53         else{
54                 $SQL_user = $config[sql_username];
55                 $SQL_passwd = $config[sql_password];
56         }
57         // FIXME: This function is still Postgres specific. Needs to be configurable.
58         return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
59                         "$SQL_user", "$SQL_passwd", DBX_PERSISTENT);
60 }
61
62 function da_sql_close($link,$config)
63 {
64         @dbx_close($link);
65 }
66
67 function da_sql_escape_string($string)
68 {
69         return addslashes($string);
70 }
71
72 function da_sql_query($link,$config,$query)
73 {
74         if ($config[sql_debug] == 'true') {
75                 print "<b>DEBUG(SQL,PG DRIVER): Query: <i>$query</i></b><br>\n";
76         }
77         return @dbx_query($link,$query);
78 }
79
80 function da_sql_num_rows($result,$config)
81 {
82         if ($config[sql_debug] == 'true')
83                 print "<b>DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . $result->rows . "</b><br>\n";
84         return $result->rows;
85 }
86
87 $dbx_global_record_counter = array() ;
88 function da_sql_fetch_array($result,$config)
89 {
90
91         global $dbx_global_record_counter;
92         if (!$dbx_global_record_counter[$result->handle]){
93                 $dbx_global_record_counter[$result->handle] = 0;
94         }
95
96         if ($dbx_global_record_counter[$result->handle] <= $result->rows - 1 ){
97                 return $result->data[$dbx_global_record_counter[$result->handle]++];
98         } elseif ($dbx_global_record_counter[$result->handle] > $result->rows - 1 ) {
99                 $dbx_global_record_counter[$result->handle]++;
100                 return NULL;
101         } else {
102                 $dbx_global_record_counter[$result->handle]++;
103                 return FALSE;
104         }
105 }
106
107 function da_sql_affected_rows($link,$result,$config)
108 {
109         // FIXME: This function is still Postgres specific.
110         if ($config[sql_debug] == 'true')
111                 print "<b>DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result->handle) . "</b><br>\n";
112         return @pg_cmdtuples($result->handle);
113 }
114
115 function da_sql_list_fields($table,$link,$config)
116 {
117         $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;"); 
118         if ($res){
119                 $fields[num] = $res->cols;
120         }
121         $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;");
122         if ($res)
123                 $fields[res] = $res->info[name];
124         else
125                 return NULL;
126
127         return $fields;
128 }
129
130 function da_sql_num_fields($fields,$config)
131 {
132         if ($fields)
133                 return $fields[num];
134 }
135
136 function da_sql_field_name($fields,$num,$config)
137 {
138         if ($fields)
139                 return $fields[res][$num];
140 }
141
142 function da_sql_error($link,$config)
143 {
144         return dbx_error($link);
145 }
146 ?>