本文整理汇总了PHP中db函数的典型用法代码示例。如果您正苦于以下问题:PHP db函数的具体用法?PHP db怎么用?PHP db使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeRegistrationForm
/**
* POST | This handles the registration with validation.
*
* @return mixed
*/
public function storeRegistrationForm()
{
$inputs = request()->get();
$validator = new RegistrationValidator();
$validation = $validator->validate($inputs);
if (count($validation)) {
session()->set('input', $inputs);
return redirect()->to(url()->previous())->withError(RegistrationValidator::toHtml($validation));
}
$token = bin2hex(random_bytes(100));
$connection = db()->connection();
try {
$connection->begin();
$user = new User();
$success = $user->create(['email' => $inputs['email'], 'password' => security()->hash($inputs['password']), 'token' => $token]);
if ($success === false) {
throw new Exception('It seems we can\'t create an account, ' . 'please check your access credentials!');
}
queue(\Components\Queue\Email::class, ['function' => 'registeredSender', 'template' => 'emails.registered-inlined', 'to' => $inputs['email'], 'url' => route('activateUser', ['token' => $token]), 'subject' => 'You are now registered, activation is required.']);
$connection->commit();
} catch (TransactionFailed $e) {
$connection->rollback();
throw $e;
} catch (Exception $e) {
$connection->rollback();
throw $e;
}
return redirect()->to(route('showLoginForm'))->withSuccess(lang()->get('responses/register.creation_success'));
}
示例2: pub_run
public function pub_run($o)
{
$this->stomp = new Stomp('tcp://network.home.micoli.org:61613');
$this->stomp->connect('guest', 'guest');
try {
$this->imapProxy->setAccount($o['account']);
$this->imapProxy->open('INBOX');
if (!$this->imapProxy->isConnected()) {
return $res;
}
$this->getLatestMails($o);
$running = true;
do {
db(date('H:i:s ') . "IN IDLE ");
$response = $this->imapProxy->idle(5 * 60);
if ($response) {
db(date('H:i:s -------------') . $response);
$this->getLatestMails($o);
} else {
db(date('H:i:s ') . 'TIMEOUT OCCURED');
}
} while ($running);
db(__CLASS__ . " " . __LINE__);
} catch (Horde_Imap_Client_Exception $e) {
db($e);
} catch (InvalidArgumentException $e) {
db($e);
}
}
示例3: _order_step_start
/**
* Order step
*/
function _order_step_start($FORCE_DISPLAY_FORM = false)
{
module('shop')->_basket_save();
$basket_contents = module('shop')->_basket_api()->get_all();
$products_ids = [];
foreach ((array) $basket_contents as $_item_id => $_info) {
if ($_info["product_id"]) {
$products_ids[$_info["product_id"]] = $_info["product_id"];
}
}
if (!empty($products_ids)) {
$products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'");
$products_atts = module('shop')->_products_get_attributes($products_ids);
$group_prices = module('shop')->_get_group_prices($products_ids);
}
$total_price = 0;
foreach ((array) $products_infos as $_info) {
$_product_id = $_info["id"];
$_info["_group_price"] = $group_prices[$_product_id][module('shop')->USER_GROUP];
$quantity = $basket_contents[$_info["id"]]["quantity"];
$price = module('shop')->_product_get_price($_info);
$dynamic_atts = [];
foreach ((array) $products_atts[$_product_id] as $_attr_id => $_attr_info) {
if ($basket_contents[$_product_id]["atts"][$_attr_info["name"]] == $_attr_info["value"]) {
$dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"];
$price += $_attr_info["price"];
}
}
$URL_PRODUCT_ID = module('shop')->_product_id_url($_info);
$products[$_info["id"]] = ["name" => _prepare_html($_info["name"]), "price" => module('shop')->_format_price($price), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($quantity), "details_link" => process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : "", "cat_name" => _prepare_html(module('shop')->_shop_cats[$_info["cat_id"]]), "cat_url" => process_url("./?object=shop&action=products_show&id=" . module('shop')->_shop_cats_all[$_info["cat_id"]]['url'])];
$total_price += $price * $quantity;
}
$replace = ["products" => $products, "total_price" => module('shop')->_format_price($total_price), "currency" => _prepare_html(module('shop')->CURRENCY), "back_link" => "./?object=shop&action=basket", "next_link" => "./?object=shop&action=order&id=delivery", "cats_block" => module('shop')->_categories_show()];
return tpl()->parse("shop/order_start", $replace);
}
示例4: user_limits_summary
/**
* Get a summary of how many accounts, graphs, pages etc the current user has.
* Does not include disabled accounts towards the limit (#217).
* May be cached per user.
*/
function user_limits_summary($user_id)
{
global $global_user_limits_summary;
if (!isset($global_user_limits_summary[$user_id])) {
$accounts = array();
foreach (account_data_grouped() as $group) {
foreach ($group as $key => $data) {
if (!isset($data['group'])) {
continue;
}
$q = db()->prepare("SELECT COUNT(*) AS c FROM " . $data['table'] . " WHERE user_id=?" . ($data['failure'] ? " AND is_disabled=0" : "") . (isset($data['query']) ? $data['query'] : ""));
$q->execute(array($user_id));
$accounts[$key] = $q->fetch();
$accounts[$key] = $accounts[$key]['c'];
if (!isset($accounts['total_' . $data['group']])) {
$accounts['total_' . $data['group']] = 0;
}
$accounts['total_' . $data['group']] += $accounts[$key];
if (!isset($data['wizard'])) {
continue;
}
if (!isset($accounts['wizard_' . $data['wizard']])) {
$accounts['wizard_' . $data['wizard']] = 0;
}
$accounts['wizard_' . $data['wizard']] += $accounts[$key];
}
}
$global_user_limits_summary[$user_id] = $accounts;
}
return $global_user_limits_summary[$user_id];
}
示例5: basket_add
function basket_add()
{
$product = db()->query_fetch("SELECT id FROM " . db('shop_products') . " WHERE active = '1' AND " . (is_numeric($_GET["id"]) ? "id=" . intval($_GET["id"]) : "url='" . _es($_GET['id']) . "'"));
if (!empty($product)) {
$_GET['id'] = $product['id'];
}
$atts = module('shop')->_products_get_attributes($product["id"]);
if ($_GET["id"]) {
$_GET["id"] = intval($_GET["id"]);
$_POST["quantity"][$_GET["id"]] = 1;
}
if (!empty($atts) && empty($_POST["atts"])) {
module('shop')->_basket_is_processed = true;
return js_redirect("./?object=shop&action=product_details&id=" . $_GET["id"]);
}
if (!empty($_POST["quantity"]) && !module('shop')->_basket_is_processed) {
foreach ((array) $_POST["quantity"] as $_product_id => $_quantity) {
$_product_id = intval($_product_id);
$_old_quantity = (int) module('shop')->_basket_api()->get($_product_id, 'quantity');
$_quantity = intval($_quantity) + intval($_old_quantity);
if ($_product_id && $_quantity) {
module('shop')->_basket_api()->set($_product_id, ["product_id" => $_product_id, "quantity" => $_quantity, "atts" => $_POST["atts"][$_product_id]]);
}
}
// Prevent double processing
module('shop')->_basket_is_processed = true;
}
return js_redirect("./?object=shop");
}
示例6: show
/**
*/
function show()
{
$filter_name = $_GET['object'] . '__' . $_GET['action'];
$default_filter = ['order_by' => 'date', 'order_direction' => 'desc'];
$sql = 'SELECT * FROM ' . db('log_auth');
return table($sql, ['filter' => (array) $_SESSION[$filter_name] + $default_filter, 'filter_params' => ['name' => 'like']])->user('user_id')->text('login')->link('group', './?object=user_groups&action=edit&id=%d', main()->get_data('user_groups'))->link('ip', './?object=' . $_GET['object'] . '&action=show_for_ip&id=%d')->date('date', ['format' => 'full', 'nowrap' => 1])->text('user_agent')->text('referer');
}
示例7: top_match
function top_match()
{
global $db, $allowHover, $llwars, $picformat, $sql_prefix;
$qry = db("SELECT s1.datum,s1.cid,s1.id,s1.bericht,s1.xonx,s1.punkte,s1.gpunkte,s1.squad_id,s2.icon,s2.name FROM " . $db['cw'] . " AS s1\n LEFT JOIN " . $db['squads'] . " AS s2 ON s1.squad_id = s2.id\n WHERE `top` = '1'\n ORDER BY RAND()");
if ($get = _fetch($qry)) {
//Clans Mod
$clandetailssql = db("SELECT clantag, gegner FROM " . $sql_prefix . "clans WHERE id LIKE " . $get['cid']);
$clans = _fetch($clandetailssql);
$squad = '_defaultlogo.jpg';
$gegner = '_defaultlogo.jpg';
foreach ($picformat as $end) {
if (file_exists(basePath . '/inc/images/clanwars/' . $get['cid'] . '_logo.' . $end)) {
$gegner = $get['cid'] . '_logo.' . $end;
}
if (file_exists(basePath . '/inc/images/squads/' . $get['squad_id'] . '_logo.' . $end)) {
$squad = $get['squad_id'] . '_logo.' . $end;
}
}
if ($allowHover == 1 || $allowHover == 2) {
$hover = 'onmouseover="DZCP.showInfo(\'<tr><td colspan=2 align=center padding=3 class=infoTop>' . jsconvert(re($get['name'])) . '<br/>vs.<br/> ' . jsconvert(re($clans['gegner'])) . '</td></tr><tr><td><b>' . _played_at . ':</b></td><td>' . date("d.m.Y H:i", $get['datum']) . _uhr . '</td></tr><tr><td><b>' . _cw_xonx . ':</b></td><td>' . jsconvert(re($get['xonx'])) . '</td></tr><tr><td><b>' . _result . ':</b></td><td>' . cw_result_nopic_raw($get['punkte'], $get['gpunkte']) . '</td></tr><tr><td><b>' . _comments_head . ':</b></td><td>' . cnt($db['cw_comments'], "WHERE cw = '" . $get['id'] . "'") . '</td></tr>\')" onmouseout="DZCP.hideInfo()"';
}
$topmatch .= show("menu/top_match", array("id" => $get['id'], "clantag" => re(cut($clans['clantag'], $llwars)), "team" => re(cut($get['name'], $llwars)), "game" => substr(strtoupper(str_replace('.' . $icon, '', re($get['icon']))), 0, 5), "id" => $get['id'], "gegner" => $gegner, "squad" => $squad, "hover" => $hover, "info" => $get['datum'] > time() ? date("d.m.Y", $get['datum']) : cw_result_nopic($get['punkte'], $get['gpunkte'])));
}
return empty($topmatch) ? '<center style="margin:3px 0">' . _no_top_match . '</center>' : '<table class="navContent" cellspacing="0">' . $topmatch . '</table>';
}
示例8: _track_error
/**
* Track user error message
*
* @param string
* @return void
*/
function _track_error($error_message = "")
{
if (empty($error_message)) {
return false;
}
// Try to get user error message source
$backtrace = debug_backtrace();
$cur_trace = $backtrace[1];
$next_trace = $backtrace[2];
// Prepare log text
$text = "## LOG STARTS AT " . date("Y-m-d H:i:s") . "; QUERY_STRING: " . $_SERVER["QUERY_STRING"] . "; REFERER: " . $_SERVER["HTTP_REFERER"] . "; USER_ID: " . main()->USER_ID . "; USER_GROUP: " . main()->USER_GROUP . "; SITE_ID: " . SITE_ID . "; USER_AGENT: " . $_SERVER["HTTP_USER_AGENT"] . " ##\r\n";
$text .= "URL: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\r\n";
$text .= "SOURCE FILE: \"" . $cur_trace["file"] . "\" at LINE " . $cur_trace["line"] . "; " . (!empty($next_trace["class"]) ? "METHOD: " . $next_trace["class"] . "->" . $next_trace["function"] : "FUNCTION: " . $next_trace["function"]) . ";\r\n";
$text .= "MESSAGE: " . $error_message . "\r\n";
$text .= "## LOG ENDS ##\r\n";
// Do add current error info to the log file
$h = fopen(INCLUDE_PATH . $this->LOG_USER_ERRORS_FILE_NAME, "a");
fwrite($h, $text);
fclose($h);
// Do store message into database (also check if that possible)
if ($this->LOG_INTO_DB && is_object(db())) {
$error_type = 0;
db()->insert_safe('log_user_errors', ['error_level' => intval($error_type), 'error_text' => $error_message, 'source_file' => $cur_trace['file'], 'source_line' => intval($cur_trace['line']), 'date' => time(), 'site_id' => (int) conf('SITE_ID'), 'user_id' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_id' : 'user_id']), 'user_group' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_group' : 'user_group']), 'is_admin' => MAIN_TYPE_ADMIN ? 1 : 0, 'ip' => common()->get_ip(), 'query_string' => WEB_PATH . '?' . $_SERVER['QUERY_STRING'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'request_uri' => $_SERVER['REQUEST_URI'], 'env_data' => $this->DB_LOG_ENV ? $this->_prepare_env() : '', 'object' => $_GET['object'], 'action' => $_GET['action']]);
}
}
示例9: InsertSalesType
function InsertSalesType($SalesTypeDetails, $user, $password)
{
$Errors = array();
$db = db($user, $password);
if (gettype($db) == 'integer') {
$Errors[0] = NoAuthorisation;
return $Errors;
}
$FieldNames = '';
$FieldValues = '';
foreach ($SalesTypeDetails as $key => $value) {
$FieldNames .= $key . ', ';
$FieldValues .= '"' . $value . '", ';
}
$sql = 'INSERT INTO salestypes (' . substr($FieldNames, 0, -2) . ') ' . 'VALUES (' . substr($FieldValues, 0, -2) . ') ';
if (sizeof($Errors) == 0) {
$result = DB_Query($sql, $db);
if (DB_error_no($db) != 0) {
$Errors[0] = DatabaseUpdateFailed;
} else {
$Errors[0] = 0;
}
}
return $Errors;
}
示例10: motm
function motm()
{
global $db, $allowHover;
$userpics = get_files(basePath . '/inc/images/uploads/userpics/');
$qry = db("SELECT * FROM " . $db['users'] . " WHERE level >= 2");
while ($rs = _fetch($qry)) {
foreach ($userpics as $userpic) {
$tmpId = intval($userpic);
if ($tmpId == $rs['id']) {
$temparr[] = $rs['id'];
$a++;
break;
}
}
}
$arrayID = rand(0, count($temparr) - 1);
$uid = $temparr[$arrayID];
$get = _fetch(db("SELECT * FROM " . $db['users'] . " WHERE id = '" . $uid . "'"));
if (!empty($get) && !empty($temparr)) {
$status = $get['status'] == 1 || $get['level'] == 1 ? _aktiv : _inaktiv;
if ($allowHover == 1) {
$info = 'onmouseover="DZCP.showInfo(\'<tr><td colspan=2 align=center padding=3 class=infoTop>' . rawautor($get['id']) . '</td></tr><tr><td width=80px><b>' . _posi . ':</b></td><td>' . getrank($get['id']) . '</td></tr><tr><td><b>' . _status . ':</b></td><td>' . $status . '</td></tr><tr><td><b>' . _age . ':</b></td><td>' . getAge($get['bday']) . '</td></tr><tr><td colspan=2 align=center>' . jsconvert(userpic($get['id'])) . '</td></tr>\')" onmouseout="DZCP.hideInfo()"';
}
$member = show("menu/motm", array("uid" => $get['id'], "upic" => userpic($get['id'], 130, 161), "info" => $info));
} else {
$member = '';
}
return empty($member) ? '' : '<table class="navContent" cellspacing="0">' . $member . '</table>';
}
示例11: action
public function action(\Baguette\Application $app, \Teto\Routing\Action $action)
{
if ($app->session->get('user_id', ['default' => false])) {
return new Response\RedirectResponse('/');
}
if (!$app->isTokenVerified) {
return new Response\RedirectResponse('/');
}
// systemは特殊なユーザーなのでログインできない
if (isset($_REQUEST['user'], $_REQUEST['password']) && $_REQUEST['user'] != 'system') {
$user = trim($_REQUEST['user']);
$pass = $_REQUEST['password'];
$query = 'SELECT * FROM `users` WHERE `slug` = ?';
$stmt = db()->prepare($query);
$stmt->execute([$user]);
if ($login = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$query = 'SELECT `password` FROM `user_passwords` WHERE `user_id` = ?';
$stmt = db()->prepare($query);
$stmt->execute([$login['id']]);
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($res && password($pass, $res['password']) === true) {
$app->refreshSession();
$app->session->set('user_id', $login['id']);
$app->session->set('user_slug', $login['slug']);
$app->session->set('user_name', $login['name']);
return new Response\RedirectResponse('/');
}
}
}
return new Response\TemplateResponse('login.tpl.html', ['user' => isset($_REQUEST['user']) ? $_REQUEST['user'] : null]);
}
示例12: is_installed
function is_installed()
{
if (!db()) {
return false;
}
return my_sql("SHOW COLUMNS FROM `user`");
}
示例13: _get_geo_data_from_db
/**
* Get geo info by IP from db
*/
function _get_geo_data_from_db($cur_ip = "")
{
$cur_ip = trim(array_pop(explode(",", preg_replace("/[^0-9\\.,]/i", "", $cur_ip))));
if (empty($cur_ip)) {
return false;
}
if ($this->_is_ip_to_skip($cur_ip)) {
return false;
}
$STORE_UNKNOWN_IPS = true;
// Also check if IP is not recognized by our system and skip it
if ($STORE_UNKNOWN_IPS && db()->query_num_rows("SELECT * FROM " . db('geo_skip_ip') . " WHERE ip = INET_ATON('" . _es($cur_ip) . "')")) {
return false;
}
// Prepare query
$sql = "SELECT * \n\t\t\tFROM " . db('geo_city_location') . " \n\t\t\tWHERE loc_id = ( \n\t\t\t\tSELECT loc_id FROM " . db('geo_city_blocks') . "\n\t\t\t\tWHERE start_ip <= INET_ATON('" . _es($cur_ip) . "') \n\t\t\t\t\tAND end_ip >= INET_ATON('" . _es($cur_ip) . "') \n\t\t\t\tLIMIT 1 \n\t\t\t)";
$A = db()->query_fetch($sql);
if (empty($A)) {
if ($STORE_UNKNOWN_IPS) {
db()->query("INSERT INTO " . db('geo_skip_ip') . " (\n\t\t\t\t\t\tip, hits\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\tINET_ATON('" . _es($cur_ip) . "'), 1\n\t\t\t\t\t) ON DUPLICATE KEY UPDATE hits = hits + 1");
}
return false;
}
$geo_data = ["country_code" => $A["country"], "country_name" => _country_name($A["country"]), "region_code" => $A["region"], "city_name" => $A["city"], "dma_code" => $A["dma_code"], "area_code" => $A["area_code"], "longitude" => $A["longitude"], "latitude" => $A["latitude"]];
return $geo_data;
}
示例14: InsertGLAccountGroup
function InsertGLAccountGroup($AccountGroupDetails, $user, $password)
{
$Errors = array();
$db = db($user, $password);
if (gettype($db) == 'integer') {
$Errors[0] = NoAuthorisation;
return $Errors;
}
foreach ($AccountGroupDetails as $key => $value) {
$AccountGroupDetails[$key] = DB_escape_string($value);
}
$Errors = VerifyAccountGroup($AccountGroupDetails['groupname'], sizeof($Errors), $Errors, $db);
$Errors = VerifyAccountSectionExists($AccountGroupDetails['sectioninaccounts'], sizeof($Errors), $Errors, $db);
if (isset($AccountGroupDetails['pandl'])) {
$Errors = VerifyPandL($AccountGroupDetails['pandl'], sizeof($Errors), $Errors);
}
$Errors = VerifyParentGroupExists($AccountGroupDetails['parentgroupname'], sizeof($Errors), $Errors, $db);
$FieldNames = '';
$FieldValues = '';
foreach ($AccountGroupDetails as $key => $value) {
$FieldNames .= $key . ', ';
$FieldValues .= '"' . $value . '", ';
}
if (sizeof($Errors) == 0) {
$sql = 'INSERT INTO accountgroups (' . substr($FieldNames, 0, -2) . ') ' . 'VALUES (' . substr($FieldValues, 0, -2) . ') ';
$result = DB_Query($sql, $db);
if (DB_error_no($db) != 0) {
$Errors[0] = DatabaseUpdateFailed;
} else {
$Errors[0] = 0;
}
}
return $Errors;
}
示例15: pertimeAction
public function pertimeAction()
{
return;
db()->exec("SELECT store_stats_graph('app', '2010-01-01', NOW()::date::text)");
// $stats = new Default_Model_AppStats($this->appType);
// $this->view->entries = $stats->perVO();
}