/** * Memperbarui record tertentu. * * @return boolean */ public function update($id, $data = []) { try { $this->db->update($this->table, $id, $data); return true; } catch (Exception $e) { die($e->getMessage); } }
public function update($tableid, $val, $data) { if (!$data) { return; } return DB::update($this->_get_table($tableid), $data, DB::field($this->_pk, $val)); }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('posts', function (Blueprint $table) { $table->renameColumn('pgp_fp', 'user_fp'); $table->index('user_fp'); }); Schema::table('users', function (Blueprint $table) { $table->renameColumn('pgp_fp', 'user_fp'); $table->index('user_fp'); }); Schema::table('bumps', function (Blueprint $table) { $table->string('user_fp', 40)->default(''); $table->index('user_fp'); }); Schema::table('subs', function (Blueprint $table) { $table->string('user_fp', 40)->default(''); $table->string('sub_fp', 40)->default(''); $table->index('user_fp'); }); Schema::table('messages', function (Blueprint $table) { $table->string('user_fp', 40)->default(''); $table->index('user_fp'); }); Schema::table('apikeys', function (Blueprint $table) { $table->string('user_fp', 40)->default(''); }); $queries = ['update posts left join users on posts.user_id = users.id set posts.user_fp = users.user_fp', 'update bumps left join users on bumps.user_id = users.id set bumps.user_fp = users.user_fp', 'update subs left join users on subs.user_id = users.id set subs.user_fp = users.user_fp', 'update subs left join users on subs.subscription_to = users.id set subs.sub_fp = users.user_fp', 'update messages left join users on messages.user_id = users.id set messages.user_fp = users.user_fp', 'update apikeys left join users on apikeys.user_id = users.id set apikeys.user_fp = users.user_fp']; foreach ($queries as $q) { DB::update($q); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function (Blueprint $table) { $table->dateTime('announcement_expires')->nullable(); }); DB::update(DB::raw("UPDATE users SET announcement_expires = DATE_ADD(announcement_start, INTERVAL 7 DAY) WHERE announcement_start IS NOT NULL")); }
public function update_by_threadtableid($threadtableid, $data, $unbuffered = false, $low_priority = false) { if (empty($data)) { return false; } return DB::update($this->_table, $data, DB::field('threadtableid', $threadtableid), $unbuffered, $low_priority); }
public function update_cpgroupid_by_cpgroupid($val, $data) { if (!is_array($data)) { return null; } return DB::update('common_admincp_member', $data, DB::field('cpgroupid', $val)); }
public function action_delete() { $district = $this->get_orm_model('district', $this->_base_url); $services = $district->services->find_all(); if ($_POST) { if (Arr::get($_POST, 'submit')) { $msg = __(Kohana::message('admin', 'district.delete_success'), array(':name' => $district->name)); $query = DB::update('services')->set(array('district_id' => NULL))->where('district_id', '=', $district->id)->execute(); $district->content->delete(); $district->delete(); if (count($services) > 0) { $msg .= __(Kohana::message('admin', 'metro.delete_success_services'), array(':count' => count($services))); } Message::set(Message::SUCCESS, $msg); } $this->request->redirect($this->_base_url); } $text = __(Kohana::message('admin', 'district.delete_question'), array(':name' => $district->name)); if (count($services) > 0) { $text .= __(Kohana::message('admin', 'metro.delete_question_services'), array(':count' => count($services))); } $this->template->title = 'Удаление округа "' . $district->name . '"'; $this->template->bc['#'] = $this->template->title; $this->view = View::factory('backend/delete')->set('from_url', $this->_base_url)->set('title', $this->template->title)->set('text', $text); $this->template->content = $this->view; }
function login() { $accessToken = Url::get('accessToken', ''); $login_info = json_decode(file_get_contents('http://ids.cpvm.vn/services/api/users/check_open_user.php?o=' . $accessToken . '&t=2')); if ($login_info->s) { $token = $login_info->v->t; //Lay thong tin user theo token $info = json_decode(file_get_contents('http://ids.cpvm.vn/services/api/users/userinfo.php?t=' . $token)); if ($info->s) { $u = $info->v->u; $user = User::getUserById($u->id); if (!$user) { // user chua co trong db => clone $data = array('id' => $u->id, 'user_name' => $u->un, 'full_name' => $u->fn, 'avatar_url' => $u->av); $id = DB::insert('account', $data); } else { DB::update('account', array('full_name' => $u->fn), 'id=' . $u->id); } $u->t = $token; //dang nhap User::LogIn2((array) $u); $_SESSION['token'] = $token; echo 1; } else { echo 0; } } else { echo 0; } exit; }
public function update_by_find($find, $data) { if (!empty($find) && !empty($data) && is_array($data)) { return DB::update($this->_table, $data, DB::field('find', $find)); } return 0; }
public function replace_orgid_by_uid($uid, $orgarr) { $orgids = array(); foreach ($orgarr as $key => $value) { $orgids[] = $key; } $Oorgids = self::fetch_orgids_by_uid($uid); if (!is_array($orgids)) { $orgids = array($orgids); } $insertids = array_diff($orgids, $Oorgids); $delids = array_diff($Oorgids, $orgids); $updateids = array_diff($orgids, $delids, $insertids); if ($delids) { DB::delete($this->_table, "uid='{$uid}' and orgid IN (" . dimplode($delids) . ")"); } foreach ($insertids as $orgid) { if ($orgid > 0) { parent::insert(array("orgid" => $orgid, 'jobid' => $orgarr[$orgid], 'uid' => $uid, 'dateline' => TIMESTAMP), 0, 1); } } foreach ($updateids as $orgid) { if ($orgid > 0) { DB::update($this->_table, array('jobid' => $orgarr[$orgid]), "orgid='{$orgid}' and uid='{$uid}'"); } } wx_updateUser($uid); return true; }
function insert($arr, $id) { global $_G; if (!$arr) { return false; } $arr['nick'] = $arr['nick'] ? trim($arr['nick']) : ''; $arr['sid'] = $arr['sid'] ? trim($arr['sid']) : ''; $arr['title'] = $arr['title'] ? trim($arr['title']) : ''; $arr['desc'] = $arr['desc'] ? trim($arr['desc']) : ''; $arr['pic_path'] = $arr['pic_path'] ? trim($arr['pic_path']) : ''; $arr['picurl'] = $arr['picurl'] ? trim($arr['picurl']) : ''; $arr['banner'] = $arr['banner'] ? trim($arr['banner']) : ''; $arr['url'] = $arr['url'] ? trim($arr['url']) : ''; $arr['start_time'] = dmktime($arr['start_time']); $arr['end_time'] = dmktime($arr['end_time']); $arr['zk'] = floatval($arr['zk']); $arr['cate'] = intval($arr['cate']); $arr['shop_type'] = intval($arr['shop_type']); $arr['hide'] = intval($arr['hide']); $arr['sort'] = intval($arr['sort']); if ($id > 0) { $id = DB::update('shop', $arr, 'id=' . $id); api_post(array('a' => 'update', 'table' => 'shop', 'data' => $arr, 'pre_key' => 'sid', 'id' => $arr['sid'], 'cache' => 'channels,all_channel')); } else { $arr['dateline'] = TIMESTAMP; $id = DB::insert('shop', $arr, 1); if ($id > 0) { api_post(array('a' => 'insert', 'table' => 'shop', 'data' => $arr, 'cache' => 'shop,shop_type', 'id' => $id)); } } return $id; }
public function save($isNewUser = false) { //create a new database object. $db = new DB(); $username = mysql_real_escape_string($this->username); $email = mysql_real_escape_string($this->email); $firstName = mysql_real_escape_string($this->firstName); $lastName = mysql_real_escape_string($this->lastName); $link = mysql_real_escape_string($this->link); $blog = mysql_real_escape_string($this->blog); //if the user is already registered and we're //just updating their info. if (!$isNewUser) { //set the data array $data = array("username" => "'{$username}'", "password" => "'{$this->hashedPassword}'", "email" => "'{$email}'", "firstName" => "'{$firstName}'", "lastName" => "'{$lastName}'", "link" => "'{$link}'", "blog" => "'{$blog}'"); //update the row in the database $db->update($data, 'users', 'id = ' . $this->id); } else { //if the user is being registered for the first time. $data = array("username" => "'{$username}'", "password" => "'{$this->hashedPassword}'", "email" => "'{$email}'", "link" => "'{$link}'", "blog" => "'{$blog}'", "firstName" => "'{$firstName}'", "lastName" => "'{$lastName}'", "join_date" => "'" . date("Y-m-d H:i:s", time()) . "'"); $this->id = $db->insert($data, 'users'); $this->joinDate = time(); } return true; }
public function update_by_aid($aid, $data) { if (($aid = dintval($aid)) && !empty($data) && is_array($data)) { return DB::update($this->_table, $data, array('aid' => $aid)); } return 0; }
public function update($tid, $pid, $data) { if (empty($data) || !is_array($data)) { return false; } DB::update('forum_trade', $data, array('tid' => $tid, 'pid' => $pid)); }
/** * {@inheritDoc} */ public function deleteTopic(EloquentTopic $topic) { // Clean and convert ids $ids = implode(',', array_filter($topic->pathExplode(), 'is_numeric')); $query = "UPDATE forums\n\t\t\t SET posts = posts - ?, topics_count = topics_count - 1\n\t\t\t WHERE id IN ({$ids})"; return \DB::update($query, [$topic->posts_count]); }
/** * Run the migrations. * * @return void */ public function up() { DB::update('UPDATE questions q JOIN categories c ON q.category = c.name SET q.category = c.id'); Schema::table('questions', function (Blueprint $table) { $table->integer('category')->change(); }); }
public function action_show() { $id = Arr::get($_GET, 'id'); $state = intval(Arr::get($_GET, 'state')); DB::update('job_columns')->set(array('show_reports' => $state))->where('id', '=', $id)->execute(); die(json_encode(array('success' => true))); }
public function update($ctid, $uid, $data, $unbuffered = false, $low_priority = false) { if (!empty($data) && is_array($data) && $ctid && $uid) { return DB::update($this->_table, $data, DB::field('ctid', $ctid) . ' AND ' . DB::field('uid', $uid), $unbuffered, $low_priority); } return !$unbuffered ? 0 : false; }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function (Blueprint $table) { $table->integer('episodevers')->after('introduction')->default(0); }); DB::update('update users set episodevers=(select count(*) from episodevers where user_id=users.id and first=1)'); }
public function action_index() { $select = DB::select()->from('imgup_config')->order_by('id', 'DESC')->limit('1')->execute()->current(); $this->template->rows = $select; if ($this->isPost()) { $post = Validate::factory($this->getPost())->filter(TRUE, 'trim')->rule('allowed_ext', 'not_empty')->rule('admin_email', 'not_empty')->rule('max_upload', 'not_empty')->rule('max_upload', 'numeric')->rule('unit', 'not_empty'); if ($post->check()) { $id = (int) $this->getPost('id'); $max_B = $this->getPost('max_upload') . ':' . $this->getPost('unit'); $set = array('allowed_ext' => trim($this->getPost('allowed_ext')), 'admin_email' => $this->getPost('admin_email'), 'max_upload' => $max_B, 'tmp_message_top' => trim($this->getPost('tmp_message_top')), 'marquee_message' => trim($this->getPost('marquee_message')), 'show_top' => (int) $this->getPost('show_top')); if ($id > 0) { DB::update('imgup_config')->set($set)->where('id', '=', $id)->execute(); Cache::instance()->delete('sys_configs'); @unlink(DOCROOT . 'cache/index.html'); @shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/index.html'); $links[] = array('text' => '返回列表', 'href' => '/admin/system'); $this->show_message('修改资料成功', 1, $links, true); } } else { // 校验失败,获得错误提示 $str = ''; $this->template->registerErr = $errors = $post->errors('admin/module'); foreach ($errors as $item) { $str .= $item . '<br>'; } $this->show_message($str); } } }
public static function change_center_resolve($ds_lead_id, $new_center, $new_agent = null, $new_senior = null) { $success = FALSE; $message = ""; // Check lead exists in Leadpool $leadpool = \DB::query("\n\t\t\tSELECT\n\t\t\t\t ClientID\n\t\t\t\t, LeadBatchID\n\t\t\t\t, LeadRef\n\t\t\t\t, LeadRef2\n\t\t\t\t, CONVERT(datetime, DateCreated, 120) AS DateCreated\n\t\t\tFROM\n\t\t\t\tBS_Leadpool_GABFS.dbo.Client_LeadDetails\n\t\t\tWHERE\n\t\t\t\tClientID = " . $ds_lead_id . "\n\t\t")->cached(0)->execute(static::$_connection); // Change LeadRef2 if ($leadpool->count() > 0) { \DB::query("UPDATE BS_Leadpool_GABFS.dbo.Client_LeadDetails SET LeadRef2='" . $new_center . "' WHERE ClientID=" . $ds_lead_id)->execute(static::$_connection); $referral_table = \DB::query("\n\t\t\t\tSELECT\n\t\t\t\t\t id\n\t\t\t\t\t, list_id\n\t\t\t\t\t, lead_id\n\t\t\t\t\t, leadpool_id\n\t\t\t\t\t, list_name\n\t\t\t\t\t, short_code\n\t\t\t\t\t, user_login\n\t\t\t\t\t, full_name\n\t\t\t\t\t, referral_date\n\t\t\t\t\t, product\n\t\t\t\tFROM\n\t\t\t\t\tDialler.dbo.referrals\n\t\t\t\tWHERE\n\t\t\t\t\tleadpool_id = " . $ds_lead_id . "\n\t\t\t")->execute(static::$_connection); $our_referral = $leadpool->as_array(); $success = TRUE; $message = ""; if ($referral_table->count() > 0) { // Update the entry // \DB::query("UPDATE Dialler.dbo.referrals SET short_code='".$new_center."', referral_date='".$our_referral[0]['DateCreated']."' WHERE leadpool_id = ".$ds_lead_id."")->execute(static::$_connection); $updateArray = array('short_code' => $new_center, 'referral_date' => $our_referral[0]['DateCreated']); if (!is_null($new_agent)) { $getStaffDetails = \DB::select('first_name', 'last_name', 'dialler_id')->from('staffs')->where('debtsolv_id', $new_agent)->execute(); $updateArray['user_login'] = $getStaffDetails[0]['dialler_id']; $updateArray['full_name'] = $getStaffDetails[0]['first_name'] . ' ' . $getStaffDetails[0]['last_name']; } \DB::update('Dialler.dbo.referrals')->set($updateArray)->where('leadpool_id', $ds_lead_id)->execute(static::$_connection); } else { // Create a new entry \DB::query("INSERT INTO Dialler.dbo.referrals\n\t\t\t\t\t( list_id\n\t\t\t\t\t,lead_id\n\t\t\t\t\t,leadpool_id\n\t\t\t\t\t,list_name\n\t\t\t\t\t,short_code\n\t\t\t\t\t,user_login\n\t\t\t\t\t,full_name\n\t\t\t\t\t,referral_date\n\t\t\t\t\t,product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t( ''\n\t\t\t\t\t, ''\n\t\t\t\t\t, " . $ds_lead_id . "\n\t\t\t\t\t, ''\n\t\t\t\t\t, '" . $new_center . "'\n\t\t\t\t\t, ''\n\t\t\t\t\t, ''\n\t\t\t\t\t, '" . $our_referral[0]['DateCreated'] . "'\n\t\t\t\t\t, 'DR')")->execute(static::$_connection); } \Cache::delete_all("disposition.report/"); } else { $success = FALSE; $message = "Leadpool ID not found!"; } return array("success" => $success, "message" => $message); }
function main() { global $_G; $id = intval($_GET['id']); if ($id < 1) { msg('ID不存在'); return false; } $cache_name = 'article_' . $id; $cache = memory('get', $cache_name); if (is_array($cache)) { $article = $cache; } else { $article = D(array('table' => 'article', 'and' => ' id = ' . $id . ' AND `hide`=0 ')); if (!$article[id]) { msg('抱歉,当前文章不存在或未审核'); } $up = D(array('and' => ' AND id <' . $id, 'table' => __CLASS__, 'order' => 'id DESC')); $down = D(array('and' => ' AND id >' . $id, 'table' => __CLASS__, 'order' => 'id ASC')); $article[up] = $up[id] ? '<a href="' . $up[id_url] . '">' . $up[title] . '</a>' : '没有了'; $article[down] = $down[id] ? '<a href="' . $down[id_url] . '">' . $down[title] . '</a>' : '没有了'; save_history(__CLASS__, $article[id]); DB::update('article', array('views' => $article[views] + 1), 'id=' . $article[id]); memory('set', $cache_name, $article); } $this->add(array('article' => $article)); seo($article['title'], $article['keywords'], $article['description']); $this->show($article['tpl']); }
/** * update account fields * * @param integer $account_id * @param array $data_fields * @return boolean */ public function updateAccountFields($account_id = '', array $data_fields = array()) { if (!is_numeric($account_id)) { return false; } // delete not exists fields. $current_af = static::getData($account_id); if ($current_af->count() > 0) { foreach ($current_af as $af) { if (!isset($data_fields[$af->field_name])) { \DB::delete(static::$_table_name)->where('account_id', $account_id)->where('field_name', $af->field_name)->execute(); } } } unset($af, $current_af); // update or insert fields. if (is_array($data_fields) && !empty($data_fields)) { foreach ($data_fields as $field_name => $field_value) { $result = \DB::select()->from(static::$_table_name)->where('account_id', $account_id)->where('field_name', $field_name)->execute(); if (count($result) <= 0) { // use insert \DB::insert(static::$_table_name)->set(['account_id' => $account_id, 'field_name' => $field_name, 'field_value' => $field_value])->execute(); } else { // use update \DB::update(static::$_table_name)->value('field_value', $field_value)->where('account_id', '=', $account_id)->where('field_name', $field_name)->execute(); } unset($result); } unset($field_name, $field_value); } return true; }
public function update_by_fid_uid($fid, $uid, $data) { if (!$fid || !$uid || !$data || !is_array($data)) { return null; } return DB::update($this->_table, $data, array('fid' => $fid, 'uid' => $uid)); }
public function update() { $db = new DB(); $data = $this->loadData(); $db->update($data, $this->tableName, 'id = ' . $this->id); return true; }
public function update_substitute_by_styleid($substitute, $id, $stylevarids = array()) { if (!is_string($substitute) || !$id) { return; } DB::update($this->_table, array('substitute' => $substitute), ($stylevarids ? DB::field('stylevarid', $stylevarids) . ' AND ' : '') . DB::field('styleid', $id)); }
public function before() { if (!User::current()) { $this->redirect('/login'); } $url = str_replace('.', '_', URL::base() . $this->request->uri()); if (isset($_GET[$url])) { unset($_GET[$url]); } if (isset($_GET[$url . '/'])) { unset($_GET[$url . '/']); } if (Group::current('is_admin') || Group::current('show_all_jobs') && Group::current('allow_finance')) { Pager::$counts[] = 2500; } if (Arr::get($_GET, 'limit') && in_array($_GET['limit'], Pager::$counts)) { DB::update('users')->set(array('list_items' => intval($_GET['limit'])))->where('id', '=', User::current('id'))->execute(); die(json_encode(array('success' => 'true'))); } if (Arr::get($_GET, 'dismiss')) { DB::delete('notifications')->where('user_id', '=', User::current('id'))->and_where('id', '=', intval($_GET['dismiss']))->execute(); die(json_encode(array('success' => 'true'))); } if (!Group::current('allow_assign')) { Enums::$statuses[Enums::STATUS_UNALLOC] = 'Not active'; } View::set_global('notifications', DB::select()->from('notifications')->where('user_id', '=', User::current('id'))->order_by('id', 'desc')->execute()); }
function usesubmit() { global $_G; $info = array('credits' => intval($_POST['credits']), 'percredit' => intval($_POST['percredit']), 'credittype' => $_G['gp_credittype'], 'left' => intval($_POST['credits']), 'magicid' => intval($this->magic['magicid']), 'receiver' => array()); if ($info['credits'] < 1) { showmessage(lang('magic/gift', 'gift_bad_credits_input')); } if ($info['percredit'] < 1 || $info['percredit'] > $info['credits']) { showmessage(lang('magic/gift', 'gift_bad_percredit_input')); } $member = array(); if (preg_match('/^extcredits[1-8]$/', $info['credittype'])) { $member = DB::fetch_first('SELECT * FROM ' . DB::table('common_member_count') . " WHERE uid = '{$_G['uid']}'"); if ($member[$info['credittype']] < $info['credits']) { showmessage(lang('magic/gift', 'gift_credits_out_of_own')); } $extcredits = str_replace('extcredits', '', $info['credittype']); updatemembercount($_G['uid'], array($extcredits => -$info['credits']), 1, 'BGC', $this->magic['magicid']); } else { showmessage(lang('magic/gift', 'gift_bad_credittype_input')); } DB::update('common_member_field_home', array('magicgift' => addslashes(serialize($info))), array('uid' => $_G['uid'])); usemagic($this->magic['magicid'], $this->magic['num']); updatemagiclog($this->magic['magicid'], '2', '1', '0', '0', 'uid', $_G['uid']); showmessage(lang('magic/gift', 'gift_succeed'), dreferer(), array(), array('showdialog' => 1, 'locationtime' => true)); }
public function update_by_pluginvarid($pluginid, $pluginvarid, $data) { if (!$pluginid || !$pluginvarid || !$data || !is_array($data)) { return; } DB::update($this->_table, $data, DB::field('pluginid', $pluginid) . ' AND ' . DB::field('pluginvarid', $pluginvarid)); }
public static function getManyToManyUpdate($arguments) { $through_table = $own_id = $foreign_id = $post_name = []; if (is_array($arguments)) { foreach ($arguments as $arg) { $through_table[] = $arg[0]; $own_id[] = $arg[1]; $foreign_id[] = $arg[2]; $post_name[] = $arg[3]; } } elseif (func_num_args() == 4) { $through_table = [func_get_arg(0)]; $own_id = [func_get_arg(1)]; $foreign_id = [func_get_arg(2)]; $post_name = [func_get_arg(3)]; } return function ($table, $post, $primaryColumn, $primary) use($through_table, $own_id, $foreign_id, $post_name) { /** * Many-to-many update first */ foreach ($through_table as $index => $ttable) { DB::delete($ttable)->where($own_id[$index], '=', $primary)->execute(); if (!empty($post[$post_name[$index]]) && $primary != 0) { foreach ($post[$post_name[$index]] as $id) { DB::insert($ttable)->values([$own_id[$index] => $primary, $foreign_id[$index] => $id])->execute(); } unset($post[$post_name[$index]]); } } /** * Regular update */ DB::update($table)->set($post)->where($primaryColumn, '=', $primary)->execute(); }; }