本文整理汇总了PHP中Connection::HttpError方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::HttpError方法的具体用法?PHP Connection::HttpError怎么用?PHP Connection::HttpError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::HttpError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: header
<?php
require_once 'Connection.class.php';
if (isset($_GET['id'])) {
// Retrieves an image by ID from Zabbix database.
$dbh = Connection::GetDatabase();
$stmt = $dbh->prepare('
SELECT image
FROM images
WHERE imageid = :imageId
');
$stmt->bindParam(':imageId', $_GET['id']);
if (!$stmt->execute()) {
$err = $stmt->errorInfo();
Connection::HttpError(500, "Failed to query image for '{$_GET['id']}'.<br/>{$err['0']} {$err['2']}");
}
$row = $stmt->fetch(PDO::FETCH_ASSOC);
header('Content-Type: image/png');
echo $row['image'];
}
示例2: CreateThresholdWeightIfNotExist
/**
* Creates entries on the tables service_weight and service_threshold if they don't exist.
* @param PDO $dbh Database connection handle.
* @param sring $serviceId ID of service to be checked.
*/
public static function CreateThresholdWeightIfNotExist(PDO $dbh, $serviceId)
{
try {
$stmt_w = Connection::QueryDatabase($dbh, 'SELECT idservice FROM service_weight WHERE idservice = ?', $serviceId);
if (!$stmt_w->fetch(PDO::FETCH_NUM)) {
Connection::QueryDatabase($dbh, 'INSERT INTO service_weight (idservice) VALUES (?)', $serviceId);
}
$stmt_t = Connection::QueryDatabase($dbh, 'SELECT idservice FROM service_threshold WHERE idservice = ?', $serviceId);
if (!$stmt_t->fetch(PDO::FETCH_NUM)) {
Connection::QueryDatabase($dbh, 'INSERT INTO service_threshold (idservice) VALUES (?)', $serviceId);
}
} catch (Exception $e) {
Connection::HttpError(500, sprintf(I('Failed to verify weight/threshold for service "%s".'), $serviceId) . '<br/>' . $e->getMessage());
}
}
示例3: header
}
$out = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($out);
// list of host groups
} else {
if ($_POST['r'] == 'hosts') {
try {
$stmt = Connection::QueryDatabase(Connection::GetDatabase(), "\n\t\t\tSELECT h.hostid, h.name\n\t\t\tFROM hosts h\n\t\t\tINNER JOIN hosts_groups hg ON hg.hostid = h.hostid\n\t\t\tWHERE hg.groupid = {$_POST['group']}\n\t\t\tORDER BY h.name\n\t\t");
} catch (Exception $e) {
Connection::HttpError(500, sprintf(I('Failed to query hosts for group %s.'), $_POST['group']) . '<br/>' . $e->getMessage());
}
$out = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($out);
// list of hosts
} else {
if ($_POST['r'] == 'triggers') {
try {
$stmt = Connection::QueryDatabase(Connection::GetDatabase(), "\n\t\t\tSELECT t.triggerid, REPLACE(t.description, '{HOSTNAME}', h.host) AS description\n\t\t\tFROM triggers t\n\t\t\tINNER JOIN functions f ON f.triggerid = t.triggerid\n\t\t\tINNER JOIN items i ON i.itemid = f.itemid AND i.hostid = {$_POST['host']}\n\t\t\tINNER JOIN hosts h ON h.hostid = i.hostid\n\t\t\tORDER BY description\n\t\t");
} catch (Exception $e) {
Connection::HttpError(500, sprintf(I('Failed to query triggers host %s.'), $_POST['host']) . '<br/>' . $e->getMessage());
}
$out = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($out);
// list of triggers
}
}
}
}
示例4: service_icon
goodsla = ?
WHERE serviceid = ?
', $data->name, $data->algorithm, $data->triggerid, $data->showsla, $data->goodsla, $data->id);
Connection::QueryDatabase($dbh, 'DELETE FROM service_icon WHERE idservice = ?', $data->id);
if ($data->imageid !== null) {
Connection::QueryDatabase($dbh, 'INSERT INTO service_icon (idservice,idicon) VALUES (?,?)', $data->id, $data->imageid);
}
$dbh->commit();
} catch (Exception $e) {
$dbh->rollback();
Connection::HttpError(500, sprintf(I('Failed to update service with id=%s.<br/>%s'), $data->id, $e->getMessage()));
}
header('Content-Type: application/json');
echo json_encode(array('status' => 'ok'));
// output status
} else {
if (isset($_REQUEST['serviceId'])) {
// --- Query service information. ------------------------------------------
header('Content-Type: application/json');
echo json_encode(ServiceTree::GetInfo($dbh, $_REQUEST['serviceId']));
} else {
if (isset($_POST['images'])) {
// --- Query all available images from Zabbix. -----------------------------
header('Content-Type: application/json');
echo json_encode(ServiceTree::GetAllImages($dbh));
} else {
// --- No request? ---------------------------------------------------------
Connection::HttpError(400, I('No retrieve/save service request... what are you trying to do?'));
}
}
}
示例5: _TellDbError
/**
* Outputs latest database error.
* @param PDO $dbh Database connection handle.
* @param string $msg Additional text to be outputted.
*/
private static function _TellDbError(PDO $dbh, $msg)
{
$err = $dbh->errorInfo();
Connection::HttpError(500, "{$msg}<br/>{$err['0']} {$err['2']}");
}
示例6: session_start
<?php
session_start();
require 'inc/Connection.class.php';
require 'inc/ServiceTree.class.php';
require_once '__conf.php';
require_once 'i18n/i18n.php';
i18n_set_map('en', $LANG, false);
if (isset($_REQUEST['root'])) {
// List of root service names.
$dbh = Connection::GetDatabase();
header('Content-Type: application/json');
echo json_encode(ServiceTree::GetRootList($dbh));
} else {
if (isset($_REQUEST['serviceId']) && $_REQUEST['serviceId'] != '' || isset($_REQUEST['serviceName']) && $_REQUEST['serviceName'] != '') {
// Build and return the service tree.
// Service may be queried by its ID or name.
$dbh = Connection::GetDatabase();
$serviceId = isset($_REQUEST['serviceId']) && $_REQUEST['serviceId'] != '' ? $_REQUEST['serviceId'] : ServiceTree::GetIdByName($dbh, $_REQUEST['serviceName']);
// Output JSON data.
$statusCount = array(0, 0, 0, 0, 0, 0);
$root = ServiceTree::GetAllToHtml5($dbh, $serviceId, $statusCount);
header('Content-Type: application/json');
echo json_encode(array('tree' => $root, 'statusCount' => $statusCount));
} else {
Connection::HttpError(400, I('Service tree: no parameters, nothing to query.'));
}
}
示例7: unset
// Requests processing.
if (isset($_POST['logoff'])) {
// --- Logoff process. -----------------------------------------------------
if (isset($_SESSION['user'])) {
unset($_SESSION['user']);
// remove session data
unset($_SESSION['hash']);
}
header('Content-Type: application/json');
echo json_encode(array('status' => 'ok'));
// output status
} else {
if (isset($_POST['user']) && isset($_POST['pass'])) {
// --- Login process. ------------------------------------------------------
$zabbix = Connection::GetZabbixApi(null);
// no hash
try {
$hash = $zabbix->autenticar($_POST['user'], $_POST['pass']);
} catch (Exception $e) {
Connection::HttpError(401, sprintf(I('Zabbix login failed for user %s.'), $_POST['user']));
}
$_SESSION['user'] = $_POST['user'];
// save session data
$_SESSION['hash'] = $hash;
header('Content-Type: application/json');
echo json_encode(array('status' => 'ok', 'user' => $_POST['user'], 'hash' => $hash));
} else {
// --- No request? ---------------------------------------------------------
Connection::HttpError(400, I('No parameters... what do you want to do?'));
}
}