本文整理汇总了PHP中DBConnection::getReadConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::getReadConnection方法的具体用法?PHP DBConnection::getReadConnection怎么用?PHP DBConnection::getReadConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::getReadConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: constructSQL
//.........这里部分代码省略.........
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
$tmplink = " " . $p['link2'][$key];
}
if (!empty($HAVING)) {
$LINK = $tmplink;
}
$HAVING .= Search::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key);
} else {
// Meta Where Search
$LINK = " ";
$NOT = 0;
// Manage Link if not first item
if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) {
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
if (is_array($p['link2']) && isset($p['link2'][$key])) {
$tmplink = " " . $p['link2'][$key];
} else {
$tmplink = " AND ";
}
}
if (!empty($WHERE)) {
$LINK = $tmplink;
}
$WHERE .= Search::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1);
}
}
}
}
// Use a ReadOnly connection if available and configured to be used
$DBread = DBConnection::getReadConnection();
// If no research limit research to display item and compute number of item using simple request
$nosearch = true;
for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) {
$nosearch = false;
}
}
if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
$nosearch = false;
}
$LIMIT = "";
$numrows = 0;
//No search : count number of items using a simple count(ID) request and LIMIT search
if ($nosearch) {
$LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT;
// Force group by for all the type -> need to count only on table ID
if (!isset($searchopt[$itemtype][1]['forcegroupby'])) {
$count = "count(*)";
} else {
$count = "count(DISTINCT `{$itemtable}`.`id`)";
}
// request currentuser for SQL supervision, not displayed
$query_num = "SELECT {$count}\n FROM `{$itemtable}`" . $COMMONLEFTJOIN;
$first = true;
if (!empty($COMMONWHERE)) {
$LINK = " AND ";
if ($first) {
$LINK = " WHERE ";
$first = false;
}
$query_num .= $LINK . $COMMONWHERE;
}
示例2: constructDatas
/**
* Retrieve datas from DB : construct data array containing columns definitions and rows datas
*
* add to data array a field data containing :
* cols : columns definition
* rows : rows data
*
* @since version 0.85
*
* @param $data array of search datas prepared to get datas
*
* @return nothing
**/
static function constructDatas(array &$data)
{
global $CFG_GLPI;
if (!isset($data['sql']) || !isset($data['sql']['search'])) {
return false;
}
$data['data'] = array();
// Use a ReadOnly connection if available and configured to be used
$DBread = DBConnection::getReadConnection();
$DBread->query("SET SESSION group_concat_max_len = 16384;");
// directly increase group_concat_max_len to avoid double query
if (count($data['search']['metacriteria'])) {
foreach ($data['search']['metacriteria'] as $metacriterion) {
if ($metacriterion['link'] == 'AND NOT' || $metacriterion['link'] == 'OR NOT') {
$DBread->query("SET SESSION group_concat_max_len = 4194304;");
break;
}
}
}
$result = $DBread->query($data['sql']['search']);
/// Check group concat limit : if warning : increase limit
if ($result2 = $DBread->query('SHOW WARNINGS')) {
if ($DBread->numrows($result2) > 0) {
$res = $DBread->fetch_assoc($result2);
if ($res['Code'] == 1260) {
$DBread->query("SET SESSION group_concat_max_len = 8194304;");
$result = $DBread->query($data['sql']['search']);
}
}
}
if ($result) {
$data['data']['totalcount'] = 0;
// if real search or complete export : get numrows from request
if (!$data['search']['no_search'] || $data['search']['export_all']) {
$data['data']['totalcount'] = $DBread->numrows($result);
} else {
if (!isset($data['sql']['count']) || count($data['sql']['count']) == 0) {
$data['data']['totalcount'] = $DBread->numrows($result);
} else {
foreach ($data['sql']['count'] as $sqlcount) {
$result_num = $DBread->query($sqlcount);
$data['data']['totalcount'] += $DBread->result($result_num, 0, 0);
}
}
}
// Search case
$data['data']['begin'] = $data['search']['start'];
$data['data']['end'] = min($data['data']['totalcount'], $data['search']['start'] + $data['search']['list_limit']) - 1;
// No search Case
if ($data['search']['no_search']) {
$data['data']['begin'] = 0;
$data['data']['end'] = min($data['data']['totalcount'] - $data['search']['start'], $data['search']['list_limit']) - 1;
}
// Export All case
if ($data['search']['export_all']) {
$data['data']['begin'] = 0;
$data['data']['end'] = $data['data']['totalcount'] - 1;
}
// Get columns
$data['data']['cols'] = array();
$num = 0;
$searchopt =& self::getOptions($data['itemtype']);
foreach ($data['toview'] as $key => $val) {
$data['data']['cols'][$num] = array();
$data['data']['cols'][$num]['itemtype'] = $data['itemtype'];
$data['data']['cols'][$num]['id'] = $val;
$data['data']['cols'][$num]['name'] = $searchopt[$val]["name"];
$data['data']['cols'][$num]['meta'] = 0;
$data['data']['cols'][$num]['searchopt'] = $searchopt[$val];
$num++;
}
// Display columns Headers for meta items
$already_printed = array();
if (count($data['search']['metacriteria'])) {
foreach ($data['search']['metacriteria'] as $metacriteria) {
if (isset($metacriteria['itemtype']) && !empty($metacriteria['itemtype']) && isset($metacriteria['value']) && strlen($metacriteria['value']) > 0) {
if (!isset($already_printed[$metacriteria['itemtype'] . $metacriteria['field']])) {
$searchopt =& self::getOptions($metacriteria['itemtype']);
$data['data']['cols'][$num]['itemtype'] = $metacriteria['itemtype'];
$data['data']['cols'][$num]['id'] = $metacriteria['field'];
$data['data']['cols'][$num]['name'] = $searchopt[$metacriteria['field']]["name"];
$data['data']['cols'][$num]['meta'] = 1;
$data['data']['cols'][$num]['searchopt'] = $searchopt[$metacriteria['field']];
$num++;
$already_printed[$metacriteria['itemtype'] . $metacriteria['field']] = 1;
}
}
//.........这里部分代码省略.........
示例3: __
if ($col) {
echo "<th>{$col}</th>";
}
echo "<th>" . __('Last inventory date', 'reports') . "</th>";
if ($canedit) {
echo "<th> </th>";
}
echo "<th class='blue'>" . __('ID') . "</th>" . "<th class='blue'>" . __('Name') . "</th>" . "<th class='blue'>" . __('Manufacturer') . "</th>" . "<th class='blue'>" . __('Inventory number') . "</th>" . "<th class='blue'>" . __('Serial number') . "</th>" . "<th class='blue'>" . __('Inventory number') . "</th>";
if ($col) {
echo "<th class='blue'>{$col}</th>";
}
echo "<th class='blue'>" . __('Last inventory date', 'reports') . "</th>";
echo "</tr>\n";
if (method_exists('DBConnection', 'getReadConnection')) {
// In 0.80
$DBread = DBConnection::getReadConnection();
} else {
$DBread = $DB;
}
$comp = new Computer();
$result = $DBread->query($Sql);
for ($prev = -1, $i = 0; $data = $DBread->fetch_array($result); $i++) {
if ($prev != $data["entity"]) {
$prev = $data["entity"];
echo "<tr class='tab_bg_4'><td class='center' colspan='{$colspan}'>" . Dropdown::getDropdownName("glpi_entities", $prev) . "</td></tr>\n";
}
echo "<tr class='tab_bg_2'>";
if ($canedit) {
echo "<td><input type='checkbox' name='item[" . $data["AID"] . "]' value='1'></td>";
}
echo "<td class='b'>" . $data["AID"] . "</td>";
示例4: showList
//.........这里部分代码省略.........
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
$tmplink = " " . $p['link2'][$key];
}
if (!empty($HAVING)) {
$LINK = $tmplink;
}
$HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key);
} else {
// Meta Where Search
$LINK = " ";
$NOT = 0;
// Manage Link if not first item
if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) {
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
if (is_array($p['link2']) && isset($p['link2'][$key])) {
$tmplink = " " . $p['link2'][$key];
} else {
$tmplink = " AND ";
}
}
if (!empty($WHERE)) {
$LINK = $tmplink;
}
$WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1);
}
}
}
}
// Use a ReadOnly connection if available and configured to be used
$DBread = DBConnection::getReadConnection();
// If no research limit research to display item and compute number of item using simple request
$nosearch = true;
for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) {
$nosearch = false;
}
}
if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
$nosearch = false;
}
$LIMIT = "";
$numrows = 0;
//No search : count number of items using a simple count(ID) request and LIMIT search
if ($nosearch) {
$LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT;
// Force group by for all the type -> need to count only on table ID
if (!isset($searchopt[$itemtype][1]['forcegroupby'])) {
$count = "count(*)";
} else {
$count = "count(DISTINCT `{$itemtable}`.`id`)";
}
// request currentuser for SQL supervision, not displayed
$query_num = "SELECT {$count},\n '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN;
$first = true;
if (!empty($COMMONWHERE)) {
$LINK = " AND ";
if ($first) {
$LINK = " WHERE ";
$first = false;
}
$query_num .= $LINK . $COMMONWHERE;
}
示例5: showList
//.........这里部分代码省略.........
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
$tmplink = " " . $p['link2'][$key];
}
if (!empty($HAVING)) {
$LINK = $tmplink;
}
$HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key);
} else {
// Meta Where Search
$LINK = " ";
$NOT = 0;
// Manage Link if not first item
if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) {
$tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
$NOT = 1;
} else {
if (is_array($p['link2']) && isset($p['link2'][$key])) {
$tmplink = " " . $p['link2'][$key];
} else {
$tmplink = " AND ";
}
}
if (!empty($WHERE)) {
$LINK = $tmplink;
}
$WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1);
}
}
}
}
// Use a ReadOnly connection if available and configured to be used
$DBread = DBConnection::getReadConnection();
// If no research limit research to display item and compute number of item using simple request
$nosearch = true;
for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) {
$nosearch = false;
}
}
if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
$nosearch = false;
}
$LIMIT = "";
$numrows = 0;
//No search : count number of items using a simple count(ID) request and LIMIT search
if ($nosearch) {
$LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT;
// Force group by for all the type -> need to count only on table ID
if (!isset($searchopt[$itemtype][1]['forcegroupby'])) {
$count = "count(*)";
} else {
$count = "count(DISTINCT `{$itemtable}`.`id`)";
}
// request currentuser for SQL supervision, not displayed
$query_num = "SELECT {$count}, '" . $_SESSION['glpiname'] . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN;
$first = true;
if (!empty($COMMONWHERE)) {
$LINK = " AND ";
if ($first) {
$LINK = " WHERE ";
$first = false;
}
$query_num .= $LINK . $COMMONWHERE;
}
示例6: isThisItemCheckRule
static function isThisItemCheckRule($parm)
{
global $DB;
$itemtype = get_class($parm);
$items_id = $parm->fields['id'];
$session_glpisearch = array();
if (isset($_SESSION['glpisearch'])) {
$session_glpisearch = $_SESSION['glpisearch'];
}
$session_glpisearchcount = array();
if (isset($_SESSION['glpisearchcount'])) {
$session_glpisearchcount = $_SESSION['glpisearchcount'];
}
$session_glpisearchcount2 = array();
if (isset($_SESSION['glpisearchcount2'])) {
$session_glpisearchcount2 = $_SESSION['glpisearchcount2'];
}
$a_find = array();
$pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule();
$pmComponentscatalog = new PluginMonitoringComponentscatalog();
$query = "SELECT * FROM `" . $pmComponentscatalog_rule->getTable() . "`\n WHERE `itemtype`='" . $itemtype . "'";
$result = $DB->query($query);
$get_tmp = array();
if (isset($_GET)) {
$get_tmp = $_GET;
}
while ($data = $DB->fetch_array($result)) {
if (!isset($_SESSION['glpiactiveentities_string'])) {
$_SESSION['glpiactiveentities_string'] = $parm->fields['entities_id'];
}
// Load right entity
$pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']);
$default_entity = 0;
if (isset($_SESSION['glpiactive_entity'])) {
$default_entity = $_SESSION['glpiactive_entity'];
}
$entities_isrecursive = 0;
if (isset($_SESSION['glpiactiveentities']) and count($_SESSION['glpiactiveentities']) > 1) {
$entities_isrecursive = 1;
}
if (!isset($_SESSION['glpiactiveprofile']['entities'])) {
$_SESSION['glpiactiveprofile']['entities'] = array($pmComponentscatalog->fields['entities_id'] => array('id' => $pmComponentscatalog->fields['entities_id'], 'name' => '', 'is_recursive' => $pmComponentscatalog->fields['is_recursive']));
}
Session::changeActiveEntities($pmComponentscatalog->fields['entities_id'], $pmComponentscatalog->fields['is_recursive']);
$itemtype = $data['itemtype'];
$condition = importArrayFromDB($data['condition']);
$params = Search::manageParams($itemtype, $condition, FALSE);
$datar = Search::prepareDatasForSearch($itemtype, $params);
Search::constructSQL($datar);
$DBread = DBConnection::getReadConnection();
$DBread->query("SET SESSION group_concat_max_len = 16384;");
$resultr = $DBread->query($datar['sql']['search']);
/// Check group concat limit : if warning : increase limit
if ($result2 = $DBread->query('SHOW WARNINGS')) {
if ($DBread->numrows($result2) > 0) {
$res = $DBread->fetch_assoc($result2);
if ($res['Code'] == 1260) {
$DBread->query("SET SESSION group_concat_max_len = 4194304;");
$resultr = $DBread->query($datar['sql']['search']);
}
}
}
$find = 0;
while ($datar = $DB->fetch_array($resultr)) {
if ($datar['id'] == $items_id) {
$find = 1;
break;
}
}
if ($find == 1) {
$a_find[$data['plugin_monitoring_componentscalalog_id']] = 1;
} else {
if (!isset($a_find[$data['plugin_monitoring_componentscalalog_id']])) {
$a_find[$data['plugin_monitoring_componentscalalog_id']] = 0;
}
}
// Reload current entity
Session::changeActiveEntities($default_entity, $entities_isrecursive);
}
if (count($get_tmp) > 0) {
$_GET = $get_tmp;
}
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
foreach ($a_find as $componentscalalog_id => $is_present) {
if ($is_present == '0') {
// * Remove from dynamic if present
$query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n AND`is_static`='0'";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
$pmComponentscatalog_Host->delete(array('id' => $data['id']));
}
} else {
// add if not present
$query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n LIMIT 1";
$result = $DB->query($query);
if ($DB->numrows($result) == '0') {
$input = array();
$input['plugin_monitoring_componentscalalog_id'] = $componentscalalog_id;
$input['is_static'] = '0';
$input['items_id'] = $items_id;
//.........这里部分代码省略.........