本文整理汇总了PHP中Database::Instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::Instance方法的具体用法?PHP Database::Instance怎么用?PHP Database::Instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::Instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Page
public function Page($template, $variables, $title, $languageFiles, $extraScripts = '', $showTopNavigation = true, $isInGame = false, $extraMetaTags = '')
{
global $NN_config;
$this->_languageFiles = $languageFiles;
$currentUser = User::GetCurrentUser();
$userLevelName = $currentUser->AuthorisationLevelName();
// Get name of userlevel
// TODO: have this use $currentUser
//$userLevelName = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = ".$currentUser->AuthorisationLevel().";","SELECT");
$resultSet = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = 0;", "SELECT");
$userLevelName = $resultSet['name'];
if ($userLevelName == NULL) {
return null;
}
// Load common variables
$CommonVariables = self::CommonFiles();
// Render the header, add it to the content
$this->_content = $this->RenderHeader($CommonVariables, $title, $userLevelName, $extraMetaTags, $extraScripts);
// If we are in the game, render the side bar
if ($isInGame) {
$this->_content .= $this->RenderSidebar($CommonVariables, $userLevelName);
}
// If required, render the top navigation bar
if ($showTopNavigation) {
// Load navigation variables
$variables['TODO'] = "add some variables";
}
// Render the actual content
$this->_content .= $this->RenderContent($CommonVariables, $template, $variables, $userLevelName);
// Render the footer
$this->_content .= $this->RenderFooter($CommonVariables, $userLevelName);
}
示例2: rearrange
function rearrange($target_id, $before_or_after)
{
access::verify_csrf();
$target = ORM::factory("item", $target_id);
$album = $target->parent();
access::required("view", $album);
access::required("edit", $album);
$source_ids = $this->input->post("source_ids", array());
if ($album->sort_column != "weight") {
$i = 0;
foreach ($album->children() as $child) {
// Do this directly in the database to avoid sending notifications
Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id));
}
$album->sort_column = "weight";
$album->sort_order = "ASC";
$album->save();
$target->reload();
}
// Find the insertion point
$target_weight = $target->weight;
if ($before_or_after == "after") {
$target_weight++;
}
// Make a hole
$count = count($source_ids);
Database::Instance()->query("UPDATE {items} " . "SET `weight` = `weight` + {$count} " . "WHERE `weight` >= {$target_weight} AND `parent_id` = {$album->id}");
// Insert source items into the hole
foreach ($source_ids as $source_id) {
Database::Instance()->update("items", array("weight" => $target_weight++), array("id" => $source_id));
}
module::event("album_rearrange", $album);
print json_encode(array("grid" => self::_get_micro_thumb_grid($album, 0)->__toString(), "sort_column" => $album->sort_column, "sort_order" => $album->sort_order));
}
示例3: GetScheduledLevelsInDatabase
public function GetScheduledLevelsInDatabase()
{
$type = $this->ID();
$query = "SELECT SUM(amount_requested) AS total_amount FROM production_building WHERE resource_type_being_built = {$type};";
$result = Database::Instance()->ExecuteQuery($query, "SELECT");
if ($result['total_amount'] === NULL) {
return 0;
} else {
return (int) $result['total_amount'];
}
}
示例4: GetDefensesOfColony
public static function GetDefensesOfColony(Colony $colony)
{
$id = $colony->ID();
$query = "SELECT * FROM colony_defences WHERE colonyID = {$id};";
$row = Database::Instance()->ExecuteQuery($query, "SELECT");
$row = array_slice($row, 1);
// Get rid of colonyID
// TODO: put these numbers in the config files or game resources,
// otherwise when you add a new weapon you need to change all these.
$row = array_slice($row, 0, 8);
// Get rid of missiles
return CombatGroup::FromList($row, $colony);
}
示例5: Work
public function Work()
{
// check for double run
if ($this->initialized) {
throw new Exception("Engine already initialized");
}
$this->initialized = true;
// Start buffer
ob_start();
// Init self variables
//$this->Debug($_SERVER, '$_SERVER');
$this->root = $_SERVER["DOCUMENT_ROOT"];
// Init autoload classes
spl_autoload_register([$this, 'AutoloadClass']);
$this->RegisterModuleClasses('system');
//$this->Debug($this->classes, '$this->classes');
// Init database connector
$requisites = (include $this->DetectFilePath('config/database.php'));
$this->DB = Database::Instance($requisites);
//$this->Debug(Database::Instance()->Query('SELECT * FROM user;', 'wef'), '$test');
// Init user session
session_start();
// Check access
$this->ACCESS = (require $this->FindClosestFile($_SERVER['REQUEST_URI'], '.access.php'));
// ...
// Load section info
$this->SECTION = (require $this->FindClosestFile($_SERVER['REQUEST_URI'], '.section.php'));
$this->SECTION['NAME'] = $this->SECTION['NAME'] ?: 'Specify section name in .section.php';
$this->SECTION['TEMPLATE'] = $this->SECTION['TEMPLATE'] ?: 'bootstrap';
// Init other modules
// ...
Modules::Instance()->Synchronize(true);
$this->LoadModules();
// Start output CONTENT
$request_uri = $this->root . $_SERVER['REQUEST_URI'];
if (file_exists($request_uri) and !is_dir($request_uri)) {
require $request_uri;
} elseif (is_dir($request_uri) and file_exists($request_uri . 'index.php')) {
require $request_uri . 'index.php';
} else {
// otherwise require closest controller.php
require $this->FindClosestFile($_SERVER['REQUEST_URI'], 'controller.php');
}
$this->CONTENT = ob_get_clean();
// Launch wrapper if it needs
// ...
require $this->DetectFilePath('templates/' . $this->SECTION['TEMPLATE'] . '/wrapper.php');
// Do last triggers
// ...
}
示例6: index
function index()
{
$group_category = (int) @$_GET['cat_group_category'];
$input = Input::Instance();
$category = new Category();
$db = Database::Instance();
$return = array();
$msgerror = null;
$searchtxt = $input->get($this->inputtext);
$liked = array("name_product" => $searchtxt, 'description_product' => $searchtxt);
$likedstr = " (\n name_product LIKE '%{$searchtxt}%' OR description_product LIKE '%{$searchtxt}%' OR\n name_product_en LIKE '%{$searchtxt}%' OR description_product_en LIKE '%{$searchtxt}%'\n ) ";
/* Count of Rows */
$result = $db->select("count(*) as total")->from("product")->where($likedstr);
if ($group_category > 0) {
$result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product");
}
$result = $result->get();
foreach ($result as $row) {
$total = $row->total;
}
/* Class Pagination */
$this->pages = new Pagination(array('base_url' => "" . $this->__("search") . "/items/" . $this->__("page") . "/", 'uri_segment' => 'pagina', 'total_items' => $total, 'items_per_page' => $category->max_items_per_category, 'style' => $category->getstyle_pagination()));
/* List of Products */
$result = $db->select("*")->from("product")->orderby(array("update_product" => "DESC"))->where("{$likedstr}")->limit($category->max_items_per_category)->offset($this->pages->sql_offset);
/*Condition Category group*/
if ($group_category > 0) {
$result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product");
}
/* Build The Result */
$result = $result->get();
foreach ($result as $row) {
Basic::currency($row->price_product);
if ($row->price_offer_product > 0) {
Basic::currency($row->price_offer_product);
$row->price_product = "<strike>" . $row->price_product . "</strike> {$this->separator_price} " . $row->price_offer_product;
}
$row->href_add_product = url::base() . $this->__("cart") . "/" . $this->__("add") . "/id/{$row->id_product}";
$row->href_detail_product = url::base() . $this->__("product") . "/" . $this->__("detail") . "/" . Basic::urlizar($row->name_product) . "/id/{$row->id_product}";
$return[] = $row;
}
/* Error Detecting */
if (count($return) < 1 or $searchtxt == null) {
$return = array();
$msgerror = __("No se encontraron resultados", false);
$this->pages = null;
}
// $this->content = View::factory("main/search_list_products")
$this->title = __('Resultados de la búsqueda', false);
$this->content = View::factory("main/list_products")->set('product', $return)->set('title', __('Resultados de la búsqueda', false))->set('msgerror', $msgerror)->set('pages', $this->pages)->render();
}
示例7: delete
/**
* Overload ORM::delete() to trigger an item_related_update event for all items that are
* related to this tag.
*/
public function delete()
{
$related_item_ids = array();
$db = Database::Instance();
foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
$related_item_ids[$row->item_id] = 1;
}
$result = parent::delete();
if ($related_item_ids) {
foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) {
module::event("item_related_update", $item);
}
}
return $result;
}
示例8: BuildTime
public function BuildTime(BuildItem $item)
{
// Calculate next build level
$nextBuildLevel = $this->GetNextBuildLevel($group);
// Calculate costs
$buildCosts = $this->BuildCost($group, $nextBuildLevel);
// Calculate time required
$colony =& $item->BuildGroup()->Colony();
$interGalacticLabLevel = $colony->Technologies()->GetMemberByName("intergalactic_research_network_technology")->Amount();
$researchLabs = 0;
if ($interGalacticLabLevel > 0) {
// Get all the research labs from this user
$userID = $colony->Owner()->ID();
$query = "SELECT cs.research_lab FROM colony_structures AS cs, colony AS c WHERE cs.colonyID = c.ID AND c.userID = {$userID};";
$results = Database::Instance()->ExecuteQuery($query, "SELECT");
$numberOfLabs = 0;
$labList = array();
if (isset($results['research_lab'])) {
// Single result
$labList[$numberOfLabs] = $results['research_lab'];
} else {
// List of results
foreach ($results as $result) {
$labList[$numberOfLabs] = $result['research_lab'];
$numberOfLabs++;
}
}
asort($labList);
// Sort from lowest to highest
for ($i = 0; $i <= $interGalacticLabLevel; $i++) {
$researchLabs += $labList[$lab];
}
} else {
$researchLabs = $colony->Buildings()->GetMemberByName("research_lab")->Amount();
}
global $NN_config;
$metalCost =& $buildCosts->Metal();
$crystalCost =& $buildCosts->Crystal();
$gameSpeed =& $NN_config["game_speed"];
$scientists = $colony->Owner()->Officers()->GetMemberByName("scientist")->Amount();
$timeRequired = ($metalCost + $crystalCost) / $gameSpeed * (1 / ($researchLabs + 1)) * 2;
$timeRequired = floor($timeRequired * 3600 * (1 - $scientists * 0.1));
return $timeRequired;
}
示例9: __toString
public function __toString()
{
/**
* poa = product options atributes
*/
$update_fields = array();
$db = Database::Instance();
$uri = Uri::Instance();
$string = null;
$tienda_id = (int) $uri->segment("edit");
if (request::method() == 'post' and is_array(@$_POST['igallery_h'])) {
$db->query("DELETE FROM product_images where product_id_product = {$tienda_id}");
$ic = 0;
if (@$_FILES['igallery'] != "") {
$arrf = $this->reArrayFiles($_FILES['igallery']);
}
foreach ($_POST['igallery_h'] as $value) {
// echo Kohana::debug($value);
// echo Kohana::debug($arrf[$ic]);
if (@$arrf[$ic]['name'] != "") {
$value = $this->upimg($arrf[$ic]);
}
// echo Kohana::debug($value);
// echo "INSERT INTO product_images (product_id_product ,pi_image) VALUES ('$tienda_id','$value')";
if ($value != "") {
try {
$db->query("INSERT INTO product_images (product_id_product ,pi_image) VALUES ('{$tienda_id}','{$value}')");
} catch (Exception $e) {
echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
}
}
$ic++;
}
}
try {
$r = $db->query("SELECT * FROM product_images WHERE product_id_product = {$tienda_id}");
$string = View::factory("extras/galleryimage")->set("imgs", $r)->render();
} catch (Exception $e) {
echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
}
return $string;
}
示例10: __construct
function __construct()
{
parent::__construct();
// $this->session = Session::instance();
@session_start();
$usr = @$_SESSION['usr'];
$pwd = @$_SESSION['pwd'];
$p_usr = trim($this->input->post('usr'));
$p_pwd = $this->_crypt_me(trim($this->input->post('pwd')));
if (request::method() == 'post' and $p_pwd != '' and $p_usr != '') {
$usr = trim($this->input->post('usr'));
$pwd = $this->_crypt_me(trim($this->input->post('pwd')));
}
// echo $usr;
if ($usr != '' and $pwd != '') {
$db = Database::Instance();
$rows = $db->from("admin")->where(array('usr_admin' => $usr, 'pwd_admin' => $pwd))->get();
$ct = 0;
foreach ($rows as $row) {
$ct++;
}
if ($ct > 0) {
$_SESSION['usr'] = $usr;
$_SESSION['pwd'] = $pwd;
if (Router::$method != 'panel') {
url::redirect("/admin/panel");
}
}
} else {
if (Router::$method != 'index') {
url::redirect("/admin/index");
}
}
if ($this->uri->segment('mod') == 'logout') {
$_SESSION['usr'] = null;
$_SESSION['pwd'] = null;
// fdurl::redirect("/admin/index");
}
}
示例11: _index
public function _index($page)
{
# is the page public?
if ('no' == $page->enable and !$this->client->can_edit($this->site_id)) {
Event::run('system.404');
}
$this->page_id = $page->id;
$this->page_name = $page->page_name;
$this->serve_page_cache($this->page_id);
$this->load_page_css_cache();
$_SESSION['js_files'] = array();
$data = array(' ', ' ', ' ', ' ', ' ', ' ');
$tools_array = array();
$prepend = '';
$append = '';
# plusjade rootsite account hook functionality
if (ROOTACCOUNT === $this->site_name) {
$data[1] = $this->plusjade_hook();
}
# get the tools on this page.
#$tools = ORM::factory('tool')->build_page($this->site_id, $page->id);
$tools = Database::Instance()->query("\n SELECT *, LOWER(system_tools.name) AS name, system_tools.protected, pages_tools.id AS instance_id\n FROM pages_tools \n JOIN tools ON pages_tools.tool_id = tools.id\n JOIN system_tools ON tools.system_tool_id = system_tools.id\n WHERE (page_id BETWEEN 1 AND 5 OR page_id = '{$page->id}')\n AND pages_tools.fk_site = '{$this->site_id}'\n ORDER BY pages_tools.container, pages_tools.position\n ");
# echo kohana::debug($tools); die;
# populate the data array based on tools.
if ($tools->count() > 0) {
foreach ($tools as $tool) {
# load the tool parent
$parent = ORM::factory($tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id);
if ($parent->loaded) {
# If Logged in wrap classes around tools for Javascript
# TODO: consider this with javascript
if ($this->client->can_edit($this->site_id)) {
$scope = '5' >= $tool->page_id ? 'global' : 'local';
$prepend = '<span id="instance_' . $tool->instance_id . '" class="common_tool_wrapper ' . $scope . '" rel="tool_' . $tool->tool_id . '">';
$append = '</span>';
# Throw tool into admin panel array
$tools_array[$tool->instance_id] = array('instance' => $tool->instance_id, 'tool_id' => $tool->tool_id, 'parent_id' => $tool->parent_id, 'name' => $tool->name, 'name_id' => $tool->system_tool_id, 'scope' => $scope);
}
# build tool output
$c_name = ucfirst($tool->name) . '_Controller';
$controller = new $c_name();
$output = $controller->_index($parent);
$tool_view = "{$prepend}{$output}{$append}";
# if we need to build the page_css file get the tool css.
if ($this->build_page_css) {
if ('yes' == $tool->protected) {
# does a theme css template exist?
$theme_templates = $this->assets->themes_dir("{$this->theme}/css/tool_templates");
if (file_exists("{$theme_templates}/{$parent->type}_{$parent->view}.sass")) {
$this->page_css .= Kosass::factory('compact')->compile(file("{$theme_templates}/{$parent->type}_{$parent->view}.sass"));
}
}
# does custom css file exist for tool?
$custom_file = "{$this->tool_dir}/{$tool->name}/{$tool->parent_id}/{$parent->type}_{$parent->view}.css";
if (file_exists($custom_file)) {
$this->page_css .= file_get_contents($custom_file);
}
}
} elseif ($this->client->can_edit($this->site_id)) {
# show the tool error when logged in.
$tool_view = "{$tool->name} with id: {$tool->parent_id} could not be loaded.";
}
# Add output to correct container.
# if page_id <= 5, its not a real page_id = global container.
(int) ($index = 5 <= $tool->page_id ? $tool->container : $tool->page_id);
$data[$index] .= $tool_view;
}
}
$this->load_interface($tools_array);
# cache the css for this page if set.
if ($this->build_page_css) {
file_put_contents("{$this->css_cache_dir}/{$page->id}.css", $this->page_css);
}
$this->template->title = $page->title;
$this->template->meta_tags('description', $page->meta);
$this->template->set_global('this_page_id', $page->id);
$this->save_page_as = $page->id;
$this->to_browser($data, $page->template);
}
示例12: GetListCount
public static function GetListCount(Colony $c)
{
$id = $c->ID();
$query = "SELECT COUNT(colonyID) as count FROM production_building WHERE colonyID = {$id};";
$result = Database::Instance()->ExecuteQuery($query, "SELECT");
if ($result == NULL) {
$count = 0;
} else {
$count = $result['count'];
}
}
示例13: GetColoniesWithUnfinishedActions
public function GetColoniesWithUnfinishedActions()
{
$currentTime = time();
$production = "SELECT DISTINCT colonyID AS id, 0 AS is_defender FROM production WHERE {$currentTime} > scheduled_time;";
$transports = "SELECT DISTINCT colonyID AS id, 0 AS is_defender FROM scheduled_transports WHERE {$currentTime} > scheduled_time;";
$expeditions = "SELECT DISTINCT f.colonyID AS id, 0 AS is_defender FROM scheduled_expeditions AS e, fleet AS f WHERE e.fleetID = f.fleetID AND {$currentTime} > scheduled_time;";
$attackers = "SELECT DISTINCT attackerID, 0 AS is_defender FROM scheduled_battles WHERE {$currentTime} > scheduled_time;";
$defenders = "SELECT DISTINCT defenderID, 1 AS is_defender FROM scheduled_battles WHERE {$currentTime} > scheduled_time;";
$results = array();
$queries = array($production, $transports, $expeditions, $attackers, $defenders);
foreach ($queries as $query) {
$results[] = Database::Instance()->ExecuteQuery($query, "SELECT");
}
$allColonies = array();
foreach ($results as $rows) {
if (is_array($rows) && isset($rows['id'])) {
// Just one row
$allColonies[$rows['id']] = $rows['is_defender'];
} elseif (is_array($rows)) {
foreach ($rows as $row) {
$allColonies[$row['id']] = $row['is_defender'];
}
}
}
arsort($allColonies);
// Defenders have to be updated first, so let's sort it like that.
return array_keys($allColonies);
}
示例14: UpdateDatabase
public function UpdateDatabase()
{
$list = $this->Members();
$userID = $this->Owner()->ID();
$changes = $this->Changes();
$changesNeeded = false;
$query = "UPDATE user_technology SET ";
foreach ($list as $technology) {
if ($changes[$technology->Name()] == true) {
$query .= $technology->Name() . " = " . $technology->Amount() . ", ";
$changesNeeded = true;
}
}
if ($changesNeeded) {
// Lop off last comma
$query = Helper::lop_off($query, 2);
$query .= " WHERE userID = {$userID}";
Database::Instance()->ExecuteQuery($query, "UPDATE");
}
}
示例15: DeleteItemFromDatabase
public function DeleteItemFromDatabase(BuildItem $item)
{
$colonyID = $this->BuildList()->Colony()->ID();
$type = $item->ID();
$pos = $item->OldPositionInList();
$query = "DELETE FROM production WHERE colonyID = {$colonyID} AND resource_type_being_built = {$type} AND build_list_position = {$pos};";
$result = Database::Instance()->ExecuteQuery($query, "DElETE");
}