本文整理匯總了PHP中DBselect函數的典型用法代碼示例。如果您正苦於以下問題:PHP DBselect函數的具體用法?PHP DBselect怎麽用?PHP DBselect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DBselect函數的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: _getContent
public function _getContent($refresh = false)
{
$table = new CTableInfo(_('No web scenarios found.'));
$table->setHeader(array(_('Website'), _('Links'), _('Broken Links')));
$data = array();
// fetch links between HTTP tests and host groups
$result = DbFetchArray(DBselect('SELECT website.*, sum(status LIKE "2%") as links_ok, sum(status != "" AND NOT status LIKE "2%") as links_404, sum(status = "" OR status is null) as links_unchecked FROM zabbix_spider.website LEFT JOIN zabbix_spider.page ON page.website = Website.aid group by page.website;'));
foreach ($result as $row) {
$deadlinks = DbFetchArray(DBselect('SELECT * FROM zabbix_spider.page WHERE NOT status IS NULL AND status != "200" AND status != "" and website = ' . $row['aid']));
$deadlink_output = array();
$link_options = array("target" => "_blank");
foreach ($deadlinks as $deadlink) {
$link_link = new CLink($deadlink['url'] == "" ? "root" : substr($deadlink['url'], 0, 50), ($deadlink['url'] == "" || $deadlink['url'][0] == "/" ? $row['url'] : "") . $deadlink['url']);
$link_link->setTarget("_blank");
$map_link = new CLink("map", $this->reportUrl . "?pid={$deadlink['aid']}");
$map_link->setTarget("_blank");
$info_link = new CLink($deadlink["status"], "http://www.checkupdown.com/status/E{$deadlink['status']}.html");
$info_link->setTarget("_blank");
$deadlink_output[] = new CDiv(array($link_link, " [ ", $map_link, " | ", $info_link, " ]"));
}
$link_link = new CLink($row['name'], $row['url']);
$link_link->setTarget("_blank");
$map_link = new CLink("map", $this->reportUrl . "?wid={$row['aid']}");
$map_link->setTarget("_blank");
$table->addRow(array(new CDiv(array($link_link, " [ ", $map_link, " ]")), new CDiv(array(new CSpan($row['links_ok'], 'green'), " / ", new CSpan($row['links_404'], 'red'), " / ", new CSpan($row['links_unchecked'], 'gray'))), new CDiv($deadlink_output)));
}
return $table;
}
示例4: 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;
}
示例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: 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);
}
示例7: _getContent
public function _getContent($refresh = false)
{
global $DB;
$table = new CTableInfo(_('No email log data found'));
$table->setHeader(array(_('System'), _('Interval'), _('Next Expected'), _('Last Seen'), _('Total Emails'), _('Actions')));
$data = array();
$db = mysql_connect("192.168.211.7", "zabbix", "asmd213)A)SDM@**@@");
$result = DbFetchArray(DBselect('
SELECT email_schedule.*,COUNT(email_match.schedule) as `email_count` FROM email_tracker.email_schedule LEFT JOIN email_tracker.email_match ON email_match.schedule = email_schedule.id GROUP BY email_schedule.id ORDER BY exec_order
'));
foreach ($result as $row) {
// $link_link = new CLink($row['name'],$row['url']);
// $link_link->setTarget("_blank");
// $map_link = new CLink("map","/spider_report.php?wid=$row[aid]");
// $map_link->setTarget("_blank");
$color = $row['missed'] == 0 ? 'green' : 'red';
$last_seen = empty($row['last_seen']) || $row['last_seen'] == '0000-00-00 00:00:00' ? 'Never' : $row['last_seen'];
$table->addRow(array(new CDiv($row['name']), new CDiv($row['expected_interval']), new CDiv($row['next_expected']), new CDiv(new CSpan($last_seen, $color)), new CDiv($row['email_count']), new CLink('Ack', '/zabbix/email.php?action=ack&id=' . $row['id'])));
// if (!isset($httpTestData[$row['httptestid']])) {
// $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown'];
// }
// elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) {
// $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed'];
// }
// else {
// $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok'];
// }
}
return $table;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: rightsForLink
function rightsForLink($idl)
{
$glinks = DBfetchArray(DBselect('SELECT host1, host2
FROM hosts_links WHERE hosts_links.id = ' . $idl));
if (API::Host()->isWritable(array(1 * $glinks[0]['host1'])) and API::Host()->isWritable(array(1 * $glinks[0]['host2']))) {
return true;
}
return false;
}
示例13: 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']));
}
示例14: 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;
}
示例15: 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));
}