當前位置: 首頁>>代碼示例>>PHP>>正文


PHP IPAddress::getTable方法代碼示例

本文整理匯總了PHP中IPAddress::getTable方法的典型用法代碼示例。如果您正苦於以下問題:PHP IPAddress::getTable方法的具體用法?PHP IPAddress::getTable怎麽用?PHP IPAddress::getTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在IPAddress的用法示例。


在下文中一共展示了IPAddress::getTable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createNetworkNameFromItem

/**
 * @param $itemtype
 * @param $items_id
 * @param $main_items_id
 * @param $main_itemtype
 * @param $entities_id
 * @param $IP
**/
function createNetworkNameFromItem($itemtype, $items_id, $main_items_id, $main_itemtype, $entities_id, $IP)
{
    global $migration;
    // Using gethostbyaddr() allows us to define its reald internet name according to its IP.
    //   But each gethostbyaddr() may reach several milliseconds. With very large number of
    //   Networkports or NetworkeEquipment, the migration may take several minutes or hours ...
    //$computerName = gethostbyaddr($IP);
    $computerName = $IP;
    if ($computerName != $IP) {
        $position = strpos($computerName, ".");
        $name = substr($computerName, 0, $position);
        $domain = substr($computerName, $position + 1);
        $query = "SELECT `id`\n                   FROM `glpi_fqdns`\n                   WHERE `fqdn` = '{$domain}'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == 1) {
            $data = $DB->fetch_assoc($result);
            $domainID = $data['id'];
        }
    } else {
        $name = "migration-" . str_replace('.', '-', $computerName);
        $domainID = 0;
    }
    $IPaddress = new IPAddress();
    if ($IPaddress->setAddressFromString($IP)) {
        $input = array('name' => $name, 'fqdns_id' => $domainID, 'entities_id' => $entities_id, 'items_id' => $items_id, 'itemtype' => $itemtype);
        $networknames_id = $migration->insertInTable('glpi_networknames', $input);
        $input = $IPaddress->setArrayFromAddress(array('entities_id' => $entities_id, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id), "version", "name", "binary");
        $migration->insertInTable($IPaddress->getTable(), $input);
    } else {
        // Don't add the NetworkName if the address is not valid
        addNetworkPortMigrationError($items_id, 'invalid_address');
        logNetworkPortError('invalid IP address', $items_id, $main_itemtype, $main_items_id, "{$IP}");
    }
    unset($IPaddress);
}
開發者ID:jose-martins,項目名稱:glpi,代碼行數:43,代碼來源:update_0831_084.php


注:本文中的IPAddress::getTable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。