本文整理匯總了PHP中DBfetch函數的典型用法代碼示例。如果您正苦於以下問題:PHP DBfetch函數的具體用法?PHP DBfetch怎麽用?PHP DBfetch使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DBfetch函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: bodyToString
public function bodyToString()
{
$this->cleanItems();
$total = 0;
// fetch accessible host ids
$hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'output' => array('hostid'), 'preservekeys' => true));
$hostIds = array_keys($hosts);
if (remove_nodes_from_id($this->groupid) > 0) {
$cond_from = ',hosts_groups hg';
$cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->groupid);
} else {
$cond_from = '';
$cond_where = andDbNode('h.hostid', $this->nodeid);
}
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$avail = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$notav = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$uncn = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$node = get_node_by_nodeid($this->nodeid);
$header_str = _('Hosts info') . SPACE;
if ($node > 0) {
$header_str .= '(' . $node['name'] . ')' . SPACE;
}
if (remove_nodes_from_id($this->groupid) > 0) {
$group = get_hostgroup_by_groupid($this->groupid);
$header_str .= _('Group') . SPACE . '"' . $group['name'] . '"';
} else {
$header_str .= _('All groups');
}
$header = new CCol($header_str, 'header');
if ($this->style == STYLE_HORISONTAL) {
$header->setColspan(4);
}
$this->addRow($header);
$avail = new CCol($avail . ' ' . _('Available'), 'avail');
$notav = new CCol($notav . ' ' . _('Not available'), 'notav');
$uncn = new CCol($uncn . ' ' . _('Unknown'), 'uncn');
$total = new CCol($total . ' ' . _('Total'), 'total');
if ($this->style == STYLE_HORISONTAL) {
$this->addRow(array($avail, $notav, $uncn, $total));
} else {
$this->addRow($avail);
$this->addRow($notav);
$this->addRow($uncn);
$this->addRow($total);
}
return parent::bodyToString();
}
示例2: updateMessageSettings
function updateMessageSettings($messages)
{
if (!isset($messages['enabled'])) {
$messages['enabled'] = 0;
}
if (isset($messages['triggers.severities'])) {
$messages['triggers.severities'] = serialize($messages['triggers.severities']);
}
$dbProfiles = DBselect('SELECT p.profileid,p.idx,p.source,p.value_str' . ' FROM profiles p' . ' WHERE p.userid=' . CWebUser::$data['userid'] . ' AND ' . dbConditionString('p.idx', array('web.messages')));
while ($profile = DBfetch($dbProfiles)) {
$profile['value'] = $profile['value_str'];
$dbMessages[$profile['source']] = $profile;
}
$inserts = array();
$updates = array();
foreach ($messages as $key => $value) {
$values = array('userid' => CWebUser::$data['userid'], 'idx' => 'web.messages', 'source' => $key, 'value_str' => $value, 'type' => PROFILE_TYPE_STR);
if (!isset($dbMessages[$key])) {
$inserts[] = $values;
} elseif ($dbMessages[$key]['value'] != $value) {
$updates[] = array('values' => $values, 'where' => array('profileid' => $dbMessages[$key]['profileid']));
}
}
try {
DB::insert('profiles', $inserts);
DB::update('profiles', $updates);
} catch (APIException $e) {
error($e->getMessage());
}
return $messages;
}
示例3: updateRegexp
function updateRegexp(array $regexp, array $expressions)
{
try {
$regexpId = $regexp['regexpid'];
unset($regexp['regexpid']);
// check existence
if (!getRegexp($regexpId)) {
throw new Exception(_('Regular expression does not exist.'));
}
// check required fields
$dbFields = array('name' => null);
if (!check_db_fields($dbFields, $regexp)) {
throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]');
}
// check duplicate name
$dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid')));
if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) {
throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name']));
}
rewriteRegexpExpressions($regexpId, $expressions);
DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId)));
} catch (Exception $e) {
error($e->getMessage());
return false;
}
return true;
}
示例4: doAction
protected function doAction()
{
$sortField = $this->getInput('sort', CProfile::get('web.proxies.php.sort', 'host'));
$sortOrder = $this->getInput('sortorder', CProfile::get('web.proxies.php.sortorder', ZBX_SORT_UP));
CProfile::update('web.proxies.php.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.proxies.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
$config = select_config();
$data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder, 'config' => ['max_in_table' => $config['max_in_table']]];
$data['proxies'] = API::Proxy()->get(['output' => ['proxyid', 'host', 'status', 'lastaccess', 'tls_connect', 'tls_accept'], 'selectHosts' => ['hostid', 'name', 'status'], 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]);
// sorting & paging
order_result($data['proxies'], $sortField, $sortOrder);
$url = (new CUrl('zabbix.php'))->setArgument('action', 'proxy.list');
$data['paging'] = getPagingLine($data['proxies'], $sortOrder, $url);
foreach ($data['proxies'] as &$proxy) {
order_result($proxy['hosts'], 'name');
}
unset($proxy);
// get proxy IDs for a *selected* page
$proxyIds = array_keys($data['proxies']);
if ($proxyIds) {
// calculate performance
$dbPerformance = DBselect('SELECT h.proxy_hostid,SUM(1.0/i.delay) AS qps' . ' FROM hosts h,items i' . ' WHERE h.hostid=i.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.delay<>0' . ' AND i.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE . ' AND ' . dbConditionInt('h.proxy_hostid', $proxyIds) . ' GROUP BY h.proxy_hostid');
while ($performance = DBfetch($dbPerformance)) {
$data['proxies'][$performance['proxy_hostid']]['perf'] = round($performance['qps'], 2);
}
// get items
$items = API::Item()->get(['proxyids' => $proxyIds, 'groupCount' => true, 'countOutput' => true, 'webitems' => true, 'monitored' => true]);
foreach ($items as $item) {
$data['proxies'][$item['proxy_hostid']]['item_count'] = $item['rowscount'];
}
}
$response = new CControllerResponseData($data);
$response->setTitle(_('Configuration of proxies'));
$this->setResponse($response);
}
示例5: import
/**
* Import template screens.
*
* @param array $allScreens
*
* @return void
*/
public function import(array $allScreens)
{
$screensToCreate = array();
$screensToUpdate = array();
foreach ($allScreens as $template => $screens) {
// TODO: select all at once out of loop
$dbScreens = DBselect('SELECT s.screenid,s.name FROM screens s WHERE' . ' s.templateid=' . zbx_dbstr($this->referencer->resolveTemplate($template)) . ' AND ' . dbConditionString('s.name', array_keys($screens)));
while ($dbScreen = DBfetch($dbScreens)) {
$screens[$dbScreen['name']]['screenid'] = $dbScreen['screenid'];
}
foreach ($screens as $screen) {
$screen = $this->resolveScreenReferences($screen);
if (isset($screen['screenid'])) {
$screensToUpdate[] = $screen;
} else {
$screen['templateid'] = $this->referencer->resolveTemplate($template);
$screensToCreate[] = $screen;
}
}
}
if ($this->options['templateScreens']['createMissing'] && $screensToCreate) {
API::TemplateScreen()->create($screensToCreate);
}
if ($this->options['templateScreens']['updateExisting'] && $screensToUpdate) {
API::TemplateScreen()->update($screensToUpdate);
}
}
示例6: checkDbVersionTable
/**
* Check if 'dbversion' table exists.
*
* @return boolean
*/
protected function checkDbVersionTable()
{
if (!DBfetch(DBselect("SELECT name FROM sqlite_master WHERE type='table' AND name='dbversion';"))) {
$this->setError(_('The frontend does not match Zabbix database.'));
return false;
}
return true;
}
示例7: checkConfig
/**
* Check the integrity of the table "config".
*
* @return bool
*/
public function checkConfig()
{
if (!DBfetch(DBselect('SELECT NULL FROM config c'))) {
$this->setError(_('Unable to select configuration.'));
return false;
}
return true;
}
示例8: get
/**
* Get GraphItems data
*
* @param array $options
* @return array|boolean
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('gitems' => 'gi.gitemid'), 'from' => array('graphs_items' => 'graphs_items gi'), 'where' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('graphids' => null, 'itemids' => null, 'type' => null, 'editable' => null, 'nopermissions' => null, 'selectGraphs' => null, 'output' => API_OUTPUT_EXTEND, 'expandData' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
$this->checkDeprecatedParam($options, 'expandData');
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.itemid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['from']['graphs'] = 'graphs g';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
}
// type
if (!is_null($options['type'])) {
$sqlParts['where'][] = 'gi.type=' . zbx_dbstr($options['type']);
}
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($gitem = DBfetch($dbRes)) {
if (!is_null($options['countOutput'])) {
$result = $gitem['rowscount'];
} else {
$result[$gitem['gitemid']] = $gitem;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
$result = $this->unsetExtraFields($result, array('graphid'), $options['output']);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例9: checkDbVersionTable
/**
* Check if 'dbversion' table exists.
*
* @return bool
*/
protected function checkDbVersionTable()
{
$tableExists = DBfetch(DBselect("SHOW TABLES LIKE 'dbversion'"));
if (!$tableExists) {
$this->setError(_('The frontend does not match Zabbix database.'));
return false;
}
return true;
}
示例10: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
$hostids = array();
$dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
while ($dbHostGroup = DBfetch($dbHostGroups)) {
$hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
}
return $this->getOutput(get_items_data_overview($hostids, $this->screenitem['style']));
}
示例11: get_image_by_imageid
function get_image_by_imageid($imageid)
{
$sql = 'SELECT * FROM images WHERE imageid=' . $imageid;
$result = DBselect($sql);
if ($row = DBfetch($result)) {
$row['image'] = zbx_unescape_image($row['image']);
}
return $row;
}
示例12: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
$hostids = array();
$dbHostGroups = DBselect('SELECT DISTINCT hg.hostid' . ' FROM hosts_groups hg' . ' WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
while ($dbHostGroup = DBfetch($dbHostGroups)) {
$hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
}
return $this->getOutput(getTriggersOverview($hostids, $this->screenitem['application'], $this->pageFile, $this->screenitem['style'], $this->screenid));
}
示例13: checkDbVersionTable
/**
* Check if 'dbversion' table exists.
*
* @return boolean
*/
protected function checkDbVersionTable()
{
$tableExists = DBfetch(DBselect("SELECT table_name FROM user_tables WHERE table_name='DBVERSION'"));
if (!$tableExists) {
$this->setError(_('The frontend does not match Zabbix database.'));
return false;
}
return true;
}
示例14: bodyToString
public function bodyToString()
{
global $USER_DETAILS;
$this->cleanItems();
$total = 0;
$accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
$cond_from = '';
if (remove_nodes_from_id($this->groupid) > 0) {
$cond_from = ', hosts_groups hg ';
$cond_where = 'AND hg.hostid=h.hostid AND hg.groupid=' . $this->groupid;
} else {
$cond_where = ' AND ' . DBin_node('h.hostid', $this->nodeid);
}
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$avail = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$notav = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$uncn = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$node = get_node_by_nodeid($this->nodeid);
$header_str = S_HOSTS_INFO . SPACE;
$header_str .= S_FOR_GROUP_SMALL . SPACE . '"';
if ($node > 0) {
$header_str .= '(' . $node['name'] . ')' . SPACE;
}
if (remove_nodes_from_id($this->groupid) > 0) {
$group = get_hostgroup_by_groupid($this->groupid);
$header_str .= $group['name'] . '"';
} else {
$header_str .= S_ALL_S . '"';
}
$header = new CCol($header_str, "header");
if ($this->style == STYLE_HORISONTAL) {
$header->SetColspan(4);
}
$this->addRow($header);
$avail = new CCol($avail . ' ' . S_AVAILABLE, 'avail');
$notav = new CCol($notav . ' ' . S_NOT_AVAILABLE, 'notav');
$uncn = new CCol($uncn . ' ' . S_UNKNOWN, 'uncn');
$total = new CCol($total . ' ' . S_TOTAL, 'total');
if ($this->style == STYLE_HORISONTAL) {
$this->addRow(array($avail, $notav, $uncn, $total));
} else {
$this->addRow($avail);
$this->addRow($notav);
$this->addRow($uncn);
$this->addRow($total);
}
return parent::bodyToString();
}
示例15: get_image_by_imageid
/**
* Get image data from db, cache is used
* @param $imageid
* @return array image data from db
*/
function get_image_by_imageid($imageid)
{
static $images = array();
if (!isset($images[$imageid])) {
$row = DBfetch(DBselect('SELECT i.* FROM images i WHERE i.imageid=' . zbx_dbstr($imageid)));
$row['image'] = zbx_unescape_image($row['image']);
$images[$imageid] = $row;
}
return $images[$imageid];
}