lots of changed, though it'll probably be all backed-out because
[configmanager.git] / lib / db.php
index 58f729d..dd5b1e3 100644 (file)
@@ -2,10 +2,11 @@
 
 function db_getDB()
 {
-       global $DB_URL;
+       global $DB_URL, $IS_WEB_REQUEST;
        
        if(!isset($IS_WEB_REQUEST)) {
                // only the web requests are allowed to create dbs
+               echo "no web request, no db\n";
                return false;
        }
        
@@ -63,17 +64,40 @@ function db_insertData($tablename)
        }
        $sql .=")";
        
+       //echo "sql is $sql\n";
+       
        $db->query($sql);
 }
 
-function db_selectData($tablename, $column="", $value="")
+function db_getMaxValue($tablename, $column, $columnsel="", $wheresel="")
 {
        $db = db_getDB();
        
        if(!$db) return false;
        
+       if($columnsel != "") {
+               $extra = " where $columnsel = '$wheresel'";
+       }
+       
+       $sql = "select max($column) from \"$tablename\"$extra";
+       $res = $db->query($sql);
+       if(!$res) return false;
+       $data = $res->fetchAll();
+       
+       return $data;
+}
+
+
+function db_selectData($tablename, $column="", $value="", $orderby = "")
+{
+       $db = db_getDB();
+       
+       if(!$db) return false;
+       
+       
        if($column != "") $extra = " where $column like '%$value%'";
        else $extra = "";
+       if($orderby != "") $extra .= " order by $orderby";
        $sql = "select * from \"$tablename\"$extra";
        $res = $db->query($sql);
        if(!$res) return false;