本文整理汇总了PHP中db_query函数的典型用法代码示例。如果您正苦于以下问题:PHP db_query函数的具体用法?PHP db_query怎么用?PHP db_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fn_settings_actions_addons_access_restrictions_admin_reverse_ip_access
/**
* Reverse IP filter
*/
function fn_settings_actions_addons_access_restrictions_admin_reverse_ip_access(&$new_value, $old_value)
{
$ip = fn_get_ip(true);
if ($new_value == 'Y') {
$ip_data = db_get_row("SELECT item_id, status FROM ?:access_restriction WHERE ip_from = ?i AND ip_to = ?i AND type IN ('aas', 'aab', 'aar')", $ip['host'], $ip['host']);
if (empty($ip_data) || empty($ip_data['item_id'])) {
// Add IP
$restrict_ip = array('ip_from' => $ip['host'], 'ip_to' => $ip['host'], 'type' => 'aas', 'timestamp' => TIME, 'expires' => '0', 'status' => 'A');
$__data = array();
$__data['item_id'] = db_query("REPLACE INTO ?:access_restriction ?e", $restrict_ip);
$__data['type'] = 'aas';
foreach (fn_get_translation_languages() as $__data['lang_code'] => $_v) {
$__data['reason'] = __('store_admin', '', $__data['lang_code']);
db_query("REPLACE INTO ?:access_restriction_reason_descriptions ?e", $__data);
}
fn_set_notification('W', __('warning'), __('your_ip_added', array('[ip]' => long2ip($ip['host']))));
} elseif (empty($ip_data['status']) || $ip_data['status'] != 'A') {
// Change IP status to available
db_query("UPDATE ?:access_restriction SET ?u WHERE item_id = ?i", array('status' => 'A'), $ip_data['item_id']);
fn_set_notification('W', __('warning'), __('your_ip_enabled', array('[ip]' => long2ip($ip['host']))));
}
} else {
// Delete IP
$ips_data = db_get_array("SELECT item_id, type FROM ?:access_restriction WHERE ip_from <= ?i AND ip_to >= ?i AND type IN ('aas', 'aab', 'aar')", $ip['host'], $ip['host']);
if (!empty($ips_data)) {
foreach ($ips_data as $ip_data) {
db_query("DELETE FROM ?:access_restriction WHERE item_id = ?i", $ip_data['item_id']);
db_query("DELETE FROM ?:access_restriction_reason_descriptions WHERE item_id = ?i AND type = ?s", $ip_data['item_id'], $ip_data['type']);
}
fn_set_notification('W', __('warning'), __('your_ip_removed', array('[ip]' => long2ip($ip['host']))));
}
}
return true;
}
示例2: session_require
function session_require($req)
{
global $Language;
/*
Codendi admins always return true
*/
if (user_is_super_user()) {
return true;
}
if (isset($req['group']) && $req['group']) {
$query = "SELECT user_id FROM user_group WHERE user_id=" . user_getid() . " AND group_id=" . db_ei($req['group']);
if (isset($req['admin_flags']) && $req['admin_flags']) {
$query .= " AND admin_flags = '" . db_escape_string($req['admin_flags']) . "'";
}
if (db_numrows(db_query($query)) < 1 || !$req['group']) {
exit_error($Language->getText('include_session', 'insufficient_g_access'), $Language->getText('include_session', 'no_perm_to_view'));
}
} elseif (isset($req['user']) && $req['user']) {
if (user_getid() != $req['user']) {
exit_error($Language->getText('include_session', 'insufficient_u_access'), $Language->getText('include_session', 'no_perm_to_view'));
}
} elseif (isset($req['isloggedin']) && $req['isloggedin']) {
if (!user_isloggedin()) {
exit_error($Language->getText('include_session', 'required_login'), $Language->getText('include_session', 'login'));
}
} else {
exit_error($Language->getText('include_session', 'insufficient_access'), $Language->getText('include_session', 'no_access'));
}
}
示例3: getQueryForList
/**
* Overrides \RestfulEntityBase::getQueryForList().
*/
public function getQueryForList() {
$query = parent::getQueryForList();
// Get the configured roles.
if (!$options = $this->getPluginKey('options')) {
return $query;
}
// Get a list of role ids for the configured roles.
$roles_list = user_roles();
$selected_rids = array();
foreach ($roles_list as $rid => $role) {
if (in_array($role, $options['roles'])) {
$selected_rids[] = $rid;
}
}
if (empty($selected_rids)) {
return $query;
}
// Get the list of user ids belonging to the selected roles.
$uids = db_query('SELECT uid FROM {users_roles} WHERE rid IN (:rids)', array(
':rids' => $selected_rids,
))->fetchAllAssoc('uid');
// Restrict the list of entities to the nodes authored by any user on the
// list of users with the administrator role.
if (!empty($uids)) {
$query->propertyCondition('uid', array_keys($uids), 'IN');
}
return $query;
}
示例4: db_insert
function db_insert($table, $hash)
{
$fields = array_keys($hash);
$sql = "INSERT INTO `{$table}` (`" . implode('`,`', $fields) . "`) VALUES ('" . implode("','", $hash) . "')";
$result = db_query($sql);
return mysql_insert_id();
}
示例5: get_associations
function get_associations()
{
$d = new DBSelector();
$d->add_table('ar', 'allowable_relationship');
$d->add_table('allowable_relationship');
$d->add_table('relationship');
$d->add_table('entity');
$d->add_relation('allowable_relationship.name = "site_to_type"');
$d->add_relation('allowable_relationship.id = relationship.type');
$d->add_relation('relationship.entity_a = ' . $this->admin_page->site_id);
$d->add_relation('relationship.entity_b = ar.relationship_b');
$d->add_relation('entity.id = ar.relationship_b');
$d->add_field('entity', 'id', 'e_id');
$d->add_field('entity', 'name', 'e_name');
$d->add_field('ar', '*');
$d->add_relation('ar.relationship_a = ' . $this->admin_page->type_id);
if (reason_relationship_names_are_unique()) {
$d->add_relation('ar.type = "association"');
} else {
$d->add_relation('ar.name != "owns"');
}
$d->add_relation('(ar.custom_associator IS NULL OR ar.custom_associator = "")');
$r = db_query($d->get_query(), 'Error selecting relationships');
$return_me = array();
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$return_me[$row['id']] = $row;
}
$this->associations = $return_me;
if (empty($this->admin_page->rel_id)) {
reset($this->associations);
list($key, ) = each($this->associations);
$this->admin_page->rel_id = $key;
}
}
示例6: viewcommentaryargs_dohook
function viewcommentaryargs_dohook($hook, $args)
{
global $currentCommentaryArea;
switch ($hook) {
case 'blockcommentarea':
$currentCommentaryArea = $args['section'];
break;
case 'viewcommentary':
$accounts = db_prefix('accounts');
$commentary = db_prefix('commentary');
preg_match("/bio.php\\?char=(.*)&ret/", $args['commentline'], $matches);
$acctid = filter_var($matches[1], FILTER_SANITIZE_NUMBER_INT);
$sql = db_query_cached("SELECT login, name FROM {$accounts} WHERE acctid = {$acctid}", "commentary-author_name-{$acctid}", 86400);
$row = db_fetch_assoc($sql);
$name = $row['name'];
$login = $row['login'];
$temp = explode($row['name'], $args['commentline']);
$temp = str_replace('`3 says, "`#', '', $temp[1]);
$temp = str_replace('`3"', '', $temp);
$temp = str_replace('/me', '', $temp);
$temp = str_replace(':', '', $temp);
$temp = str_replace('</a>', '', $temp);
$temp = full_sanitize($temp);
$temp = addslashes(implode('%', str_split(trim($temp))));
$sql = db_query("SELECT commentid, comment, postdate FROM {$commentary}\n WHERE comment LIKE '%{$temp}%'\n AND section = '{$currentCommentaryArea}'");
$row = db_fetch_assoc($sql);
$args = ['commentline' => $args['commentline'], 'section' => $currentCommentaryArea, 'commentid' => $row['commentid'], 'comment' => $row['comment'], 'author_acctid' => $acctid, 'author_login' => $login, 'author_name' => $name, 'date' => $row['postdate']];
unset($row);
unset($temp);
break;
}
return $args;
}
示例7: hook_twitter_accounts
/**
* Retrieves what Twitter accounts the given user can post to.
*/
function hook_twitter_accounts($drupal_user, $full_access = FALSE) {
$accounts = array();
if (user_access('use global twitter account') &&
($name = variable_get('twitter_global_name', NULL)) &&
($pass = variable_get('twitter_global_password', NULL))) {
$accounts[$name] = array(
'screen_name' => $name,
'password' => $pass,
);
}
$sql = " SELECT ta.*, tu.uid, tu.password, tu.import FROM {twitter_user} tu ";
$sql .= "LEFT JOIN {twitter_account} ta ON (tu.screen_name = ta.screen_name) ";
$sql .= "WHERE tu.uid = %d";
if ($full_access) {
$sql .= " AND tu.password IS NOT NULL";
}
$args = array($drupal_user->uid);
$results = db_query($sql, $args);
while ($account = db_fetch_array($results)) {
$accounts[$account['screen_name']] = $account;
}
return $accounts;
}
示例8: hook_user_load
/**
* Act on user objects when loaded from the database.
*
* Due to the static cache in user_load_multiple() you should not use this
* hook to modify the user properties returned by the {users} table itself
* since this may result in unreliable results when loading from cache.
*
* @param $users
* An array of user objects, indexed by uid.
*
* @see user_load_multiple()
* @see profile_user_load()
*/
function hook_user_load($users)
{
$result = db_query('SELECT uid, foo FROM {my_table} WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
foreach ($result as $record) {
$users[$record->uid]->foo = $record->foo;
}
}
示例9: update_access_time
/**
* Function update_access_time
* This function updates the time a template was last edited
* @param array $row_edit = an array returned from a mysql query
* @return bool True or False if two params match
* @version 1.0
* @author Patrick Lockley
*/
function update_access_time($row_edit)
{
global $xerte_toolkits_site;
/* This function is called even if the template is new - in which case it fails as a record doesn't exist */
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET date_accessed=? WHERE template_id = ?", array(date('Y-m-d'), $row_edit['template_id']));
return true;
}
示例10: doVariablesCleanupByTemplate
/**
* Cleans up variables by template.
*/
public static function doVariablesCleanupByTemplate($template)
{
$result = db_query("\n SELECT name FROM {variable}\n WHERE name LIKE '" . $template . "'");
foreach ($result as $row) {
variable_del($row->name);
}
}
示例11: cw_ps_bundle_update
function cw_ps_bundle_update($product_id)
{
global $tables, $config;
$product_id = (int) $product_id;
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
cw_ps_bundle_redirect($product_id);
}
$offer_id = cw_call('cw_ps_offer_bundle_update', array($product_id, $_POST));
// Delete selected products
if (is_array($_POST['del_cond'])) {
foreach ($_POST['del_cond'] as $k => $v) {
$k = intval($k);
db_query("DELETE FROM {$tables['ps_cond_details']} WHERE offer_id='{$offer_id}' AND object_id='{$k}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'");
db_query("DELETE FROM {$tables['ps_bonus_details']} WHERE offer_id='{$offer_id}' AND object_id='{$k}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'");
}
}
$cond_products = cw_query_column("SELECT object_id FROM {$tables['ps_cond_details']} WHERE offer_id='{$offer_id}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'");
if (count($cond_products) <= 1) {
//delete offer
cw_call('cw_ps_offer_delete', array($offer_id));
}
cw_array2update('ps_offers', array('auto' => 0), "offer_id='{$offer_id}'");
// TODO: Domain assignation
cw_ps_bundle_redirect($product_id);
}
示例12: teacher_login
function teacher_login($login, $password)
{
$sql = "SELECT teacher_id FROM teachers WHERE login='%s' AND passwd='%s'";
$res = db_query($sql, $login, md5($password));
$row = mysql_fetch_assoc($res);
return $row;
}
示例13: orphans
/**
* Displays links to all products that have not been categorized.
*
* @return
* Renderable form array.
*/
public function orphans()
{
$build = array();
if ($this->config('taxonomy.settings')->get('maintain_index_table')) {
$vid = $this->config('uc_catalog.settings')->get('vocabulary');
$product_types = uc_product_types();
$field = FieldStorageConfig::loadByName('node', 'taxonomy_catalog');
//@todo - figure this out
// $field is a config object, not an array, so this doesn't work.
//$types = array_intersect($product_types, $field['bundles']['node']);
$types = $product_types;
//temporary to get this to work at all
$result = db_query('SELECT DISTINCT n.nid, n.title FROM {node_field_data} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types[]) AND txnome.vid IS NULL', [':vid' => $vid, ':types[]' => $types]);
$rows = array();
while ($node = $result->fetchObject()) {
$rows[] = $this->l($node->title, Url::fromRoute('entity.node.edit_form', ['node' => $node->nid], ['query' => ['destination' => 'admin/store/products/orphans']]));
}
if (count($rows) > 0) {
$build['orphans'] = array('#theme' => 'item_list', '#items' => $rows);
} else {
$build['orphans'] = array('#markup' => $this->t('All products are currently listed in the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>');
}
} else {
$build['orphans'] = array('#markup' => $this->t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>');
}
return $build;
}
示例14: getPeriods
function getPeriods($yr, $mo, $account, $dimension, $dimension2, $balance = false)
{
//$begin = date2sql(begin_fiscalyear());
$date13 = date('Y-m-d', mktime(0, 0, 0, $mo + 12, 1, $yr));
$date12 = date('Y-m-d', mktime(0, 0, 0, $mo + 11, 1, $yr));
$date11 = date('Y-m-d', mktime(0, 0, 0, $mo + 10, 1, $yr));
$date10 = date('Y-m-d', mktime(0, 0, 0, $mo + 9, 1, $yr));
$date09 = date('Y-m-d', mktime(0, 0, 0, $mo + 8, 1, $yr));
$date08 = date('Y-m-d', mktime(0, 0, 0, $mo + 7, 1, $yr));
$date07 = date('Y-m-d', mktime(0, 0, 0, $mo + 6, 1, $yr));
$date06 = date('Y-m-d', mktime(0, 0, 0, $mo + 5, 1, $yr));
$date05 = date('Y-m-d', mktime(0, 0, 0, $mo + 4, 1, $yr));
$date04 = date('Y-m-d', mktime(0, 0, 0, $mo + 3, 1, $yr));
$date03 = date('Y-m-d', mktime(0, 0, 0, $mo + 2, 1, $yr));
$date02 = date('Y-m-d', mktime(0, 0, 0, $mo + 1, 1, $yr));
$date01 = date('Y-m-d', mktime(0, 0, 0, $mo, 1, $yr));
if (!$balance) {
$sql = "SELECT SUM(CASE WHEN tran_date >= '{$date01}' AND tran_date < '{$date02}' THEN amount ELSE 0 END) AS per01,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date02}' AND tran_date < '{$date03}' THEN amount ELSE 0 END) AS per02,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date03}' AND tran_date < '{$date04}' THEN amount ELSE 0 END) AS per03,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date04}' AND tran_date < '{$date05}' THEN amount ELSE 0 END) AS per04,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date05}' AND tran_date < '{$date06}' THEN amount ELSE 0 END) AS per05,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date06}' AND tran_date < '{$date07}' THEN amount ELSE 0 END) AS per06,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date07}' AND tran_date < '{$date08}' THEN amount ELSE 0 END) AS per07,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date08}' AND tran_date < '{$date09}' THEN amount ELSE 0 END) AS per08,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date09}' AND tran_date < '{$date10}' THEN amount ELSE 0 END) AS per09,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date10}' AND tran_date < '{$date11}' THEN amount ELSE 0 END) AS per10,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date11}' AND tran_date < '{$date12}' THEN amount ELSE 0 END) AS per11,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date12}' AND tran_date < '{$date13}' THEN amount ELSE 0 END) AS per12\n \t\t\tFROM " . TB_PREF . "gl_trans\n\t\t\t\tWHERE account='{$account}'";
} else {
$sql = "SELECT SUM(CASE WHEN tran_date < '{$date02}' THEN amount ELSE 0 END) AS per01,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date03}' THEN amount ELSE 0 END) AS per02,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date04}' THEN amount ELSE 0 END) AS per03,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date05}' THEN amount ELSE 0 END) AS per04,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date06}' THEN amount ELSE 0 END) AS per05,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date07}' THEN amount ELSE 0 END) AS per06,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date08}' THEN amount ELSE 0 END) AS per07,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date09}' THEN amount ELSE 0 END) AS per08,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date10}' THEN amount ELSE 0 END) AS per09,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date11}' THEN amount ELSE 0 END) AS per10,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date12}' THEN amount ELSE 0 END) AS per11,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date13}' THEN amount ELSE 0 END) AS per12\n \t\t\tFROM " . TB_PREF . "gl_trans\n\t\t\t\tWHERE account='{$account}'";
}
if ($dimension != 0) {
$sql .= " AND dimension_id = " . ($dimension < 0 ? 0 : db_escape($dimension));
}
if ($dimension2 != 0) {
$sql .= " AND dimension2_id = " . ($dimension2 < 0 ? 0 : db_escape($dimension2));
}
$result = db_query($sql, "Transactions for account {$account} could not be calculated");
return db_fetch($result);
}
示例15: svn_data_get_revision_detail
function svn_data_get_revision_detail($group_id, $commit_id, $rev_id = 0, $order = '')
{
$order_str = "";
if ($order) {
if ($order != 'filename') {
// SQLi Warning: no real possibility to escape $order here.
// We rely on a proper filtering of user input by calling methods.
$order_str = " ORDER BY " . $order;
} else {
$order_str = " ORDER BY dir, file";
}
}
//check user access rights
$pm = ProjectManager::instance();
$project = $pm->getProject($group_id);
$forbidden = svn_utils_get_forbidden_paths(user_getname(), $project->getSVNRootPath());
$where_forbidden = "";
if (!empty($forbidden)) {
while (list($no_access, ) = each($forbidden)) {
$where_forbidden .= " AND svn_dirs.dir not like '%" . db_es(substr($no_access, 1)) . "%' ";
}
}
// if the subversion revision id is given then it akes precedence on
// the internal commit_id (this is to make it easy for users to build
// URL to access a revision
if ($rev_id) {
// To be done -> get the commit ID from the svn-commit table
$sql = "SELECT svn_commits.description, svn_commits.date, svn_commits.revision, svn_checkins.type,svn_checkins.commitid,svn_dirs.dir,svn_files.file " . "FROM svn_dirs, svn_files, svn_checkins, svn_commits " . "WHERE svn_checkins.fileid=svn_files.id " . "AND svn_checkins.dirid=svn_dirs.id " . "AND svn_checkins.commitid=svn_commits.id " . "AND svn_commits.revision=" . db_ei($rev_id) . " " . "AND svn_commits.group_id=" . db_ei($group_id) . " " . $where_forbidden . $order_str;
} else {
$sql = "SELECT svn_commits.description, svn_commits.date, svn_commits.revision, svn_checkins.type,svn_checkins.commitid,svn_dirs.dir,svn_files.file " . "FROM svn_dirs, svn_files, svn_checkins, svn_commits " . "WHERE svn_checkins.fileid=svn_files.id " . "AND svn_checkins.dirid=svn_dirs.id " . "AND svn_checkins.commitid=svn_commits.id " . "AND svn_commits.id=" . db_ei($commit_id) . " " . $where_forbidden . $order_str;
}
$result = db_query($sql);
return $result;
}