Add more error messages when interacting with the SQL database
[freeradius.git] / dialup_admin / lib / sql / find.php3
1 <?php
2 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
3         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
4 else{
5         echo "<b>Could not include SQL library</b><br>\n";
6         exit();
7 }
8
9 $link = @da_sql_pconnect($config);
10 if ($link){
11         if (($search_IN == 'name' || $search_IN == 'ou') && $config[sql_use_user_info_table] == 'true'){
12                 $attr = ($search_IN == 'name') ? 'Name' : 'Department';
13                 $res = @da_sql_query($link,$config,
14                 "SELECT UserName FROM $config[sql_user_info_table] WHERE
15                 $attr LIKE '%$search%' LIMIT $max_results;");
16                 if ($res){
17                         while(($row = @da_sql_fetch_array($res,$config)))
18                                 $found_users[] = $row[UserName];
19                 }
20                 else
21                         "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
22         }
23         else if ($search_IN == 'radius' && $radius_attr != ''){
24                 require("../lib/sql/attrmap.php3");
25                 if ($attrmap["$radius_attr"] == ''){
26                         $attrmap["$radius_attr"] = $radius_attr;
27                         $attr_type["$radius_attr"] = 'replyItem';
28                 }
29                 $table = ($attr_type[$radius_attr] == 'checkItem') ? $config[sql_check_table] : $config[sql_reply_table];
30                 $attr = $attrmap[$radius_attr];
31                 $res = @da_sql_query($link,$config,
32                 "SELECT UserName FROM $table WHERE Attribute = '$attr' AND Value LIKE '%$search%' LIMIT $max_results;");
33                 if ($res){
34                         while(($row = @da_sql_fetch_array($res,$config)))
35                                 $found_users[] = $row[UserName];
36                 }
37                 else
38                         "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
39         }
40 }
41 else
42         echo "<b>Could not connect to SQL database</b><br>\n";
43 ?>