query() 공개 메소드

Execute a MySQL query
public query ( $query ) : Query
$query Query to execute
리턴 Query result handler
예제 #1
0
 public function getAccountInfoColumns()
 {
     $query = "SHOW COLUMNS FROM `accountinfo`";
     $columns = $this->db->query($query);
     while ($column = $this->db->fetch_assoc($columns)) {
         $res[$column['Field']] = $column['Field'];
     }
     if (TableExists("accountinfo_config")) {
         $query = "SELECT * FROM  `accountinfo_config` ";
         $confs = $this->db->query($query);
         while ($conf = $this->db->fetch_assoc($confs)) {
             $key = "fields_" . $conf["ID"];
             if (array_key_exists($key, $res)) {
                 if ($conf["TYPE"]) {
                     $res[$key] = array("NOM" => $conf['COMMENT'], "PREFIX" => "ACCOUNT_INFO_" . $conf["NAME"] . "_");
                 } else {
                     $res[$key] = $conf['COMMENT'];
                 }
             }
         }
     }
     return $res;
 }
 /**
  * @see PluginOcsinventoryngOcsClient::getSnmp()
  * @param array $options
  * @return array
  */
 public function getSnmp($options)
 {
     if (isset($options['OFFSET'])) {
         $offset = "OFFSET  " . $options['OFFSET'];
     } else {
         $offset = "";
     }
     if (isset($options['MAX_RECORDS'])) {
         $max_records = "LIMIT  " . $options['MAX_RECORDS'];
     } else {
         $max_records = "";
     }
     if (isset($options['ORDER'])) {
         $order = $options['ORDER'];
     } else {
         $order = " LASTDATE ";
     }
     if (isset($options['FILTER'])) {
         $filters = $options['FILTER'];
         if (isset($filters['IDS']) and $filters['IDS']) {
             $ids = $filters['IDS'];
             $where_ids = " AND snmp.ID IN (";
             $where_ids .= join(',', $ids);
             $where_ids .= ") ";
         } else {
             $where_ids = "";
         }
         if (isset($filters['EXCLUDE_IDS']) and $filters['EXCLUDE_IDS']) {
             $exclude_ids = $filters['EXCLUDE_IDS'];
             $where_exclude_ids = " AND snmp.ID NOT IN (";
             $where_exclude_ids .= join(',', $exclude_ids);
             $where_exclude_ids .= ") ";
         } else {
             $where_exclude_ids = "";
         }
         if (isset($filters['DEVICEIDS']) and $filters['DEVICEIDS']) {
             $deviceids = $filters['DEVICEIDS'];
             $where_deviceids = " AND snmp.SNMPDEVICEID IN ('";
             $where_deviceids .= join('\',\'', $deviceids);
             $where_deviceids .= "') ";
         } else {
             $where_deviceids = "";
         }
         if (isset($filters['EXCLUDE_DEVICEIDS']) and $filters['EXCLUDE_DEVICEIDS']) {
             $exclude_deviceids = $filters['EXCLUDE_DEVICEIDS'];
             $where_exclude_deviceids = " AND snmp.SNMPDEVICEID NOT IN (";
             $where_exclude_deviceids .= join(',', $exclude_deviceids);
             $where_exclude_deviceids .= ") ";
         } else {
             $where_exclude_deviceids = "";
         }
         if (isset($filters['INVENTORIED_SINCE']) and $filters['INVENTORIED_SINCE']) {
             $since = $filters['INVENTORIED_SINCE'];
             $where_since = " AND (`snmp`.`LASTDATE` > ";
             $where_since .= "'" . $since . "'";
             $where_since .= ") ";
         } else {
             $where_since = "";
         }
         if (isset($filters['INVENTORIED_BEFORE']) and $filters['INVENTORIED_BEFORE']) {
             $before = $filters['INVENTORIED_BEFORE'];
             $where_before = " AND (UNIX_TIMESTAMP(`snmp`.`LASTDATE`) < (UNIX_TIMESTAMP(" . $before . ")-180";
             // $where_before .= "'" .$before. "'";
             $where_before .= ")) ";
         } else {
             $where_before = "";
         }
         if (isset($filters['CHECKSUM']) and $filters['CHECKSUM']) {
             $checksum = $filters['CHECKSUM'];
             $where_checksum = " AND ('" . $checksum . "' & snmp.CHECKSUM) ";
         } else {
             $where_checksum = "";
         }
         $where_condition = $where_ids . $where_exclude_ids . $where_deviceids . $where_exclude_deviceids . $where_checksum . $where_since . $where_before;
     } else {
         $where_condition = "";
     }
     $query = "SELECT DISTINCT snmp.ID FROM snmp, snmp_accountinfo\n                        WHERE snmp.SNMPDEVICEID NOT LIKE '\\_%'\n                        AND snmp.ID = snmp_accountinfo.SNMP_ID\n                        {$where_condition}";
     $request = $this->db->query($query);
     if ($this->db->numrows($request)) {
         $count = $this->db->numrows($request);
         $query = "SELECT DISTINCT snmp.ID, snmp.NAME FROM snmp, snmp_accountinfo\n                           WHERE snmp.SNMPDEVICEID NOT LIKE '\\_%'\n                           AND snmp.ID = snmp_accountinfo.SNMP_ID\n                           {$where_condition}\n                           ORDER BY {$order}\n                           {$max_records}  {$offset}";
         $request = $this->db->query($query);
         $this->getAccountInfoColumns();
         while ($snmpid = $this->db->fetch_assoc($request)) {
             $snmpids[] = $snmpid['ID'];
         }
         $res["TOTAL_COUNT"] = $count;
         //         if (isset($options['DISPLAY']['CHECKSUM'])) {
         //            $checksum = $options['DISPLAY']['CHECKSUM'];
         //         } else {
         //            $checksum = self::CHECKSUM_NONE;
         //         }
         //         if (isset($options['DISPLAY']['WANTED'])) {
         //            $wanted = $options['DISPLAY']['WANTED'];
         //         } else {
         //            $wanted = self::WANTED_NONE;
         //         }
         $complete = 1;
         if (isset($options['COMPLETE'])) {
             $complete = $options['COMPLETE'];
         }
         $res["SNMP"] = $this->getSnmpSections($snmpids, $complete);
     } else {
         $res = array();
     }
     return $res;
 }