/** * @param array $values * @param array $valuesUnescaped * @throws DbalException * @return bool|int|string */ public function create($values = array(), $valuesUnescaped = array()) { $this->deleteNonExistingColumns($values); $this->deleteNonExistingColumns($valuesUnescaped); if (empty($values) && empty($valuesUnescaped)) { throw new DbalException('No allowed values detected.'); } return $this->model->insert($this->table, $values, $valuesUnescaped); }
function addTo(Model $model, Model $relatedModel) { if (!$model->primaryKeyIsSet()) { $model->insert(); } if (!isset($this->through)) { $foreignKey = $this->foreignKey; $localKey = Model::primaryKeyName($model); $relatedModel->{$foreignKey} = $model->{$localKey}; $relatedModel->save(); } else { if (!$relatedModel->primaryKeyIsSet()) { $relatedModel->insert(); } // TODO: This is a shitshow. $through = new $this->through(); $localPrimaryKey = Model::primaryKeyName($model); $localForeignKey = $this->foreignKey; $through->{$localForeignKey} = $model->{$localPrimaryKey}; $relatedPrimaryKey = Model::primaryKeyName($this->through); $relatedForeignKey = Model::getRelationship($this->through, Inflector::toSingular($this->name))->foreignKey; $through->{$relatedForeignKey} = $relatedModel->{$relatedPrimaryKey}; $through->insert(); } return $model; }
public function insert(array $params = []) { if ($instance = parent::insert($params)) { $data = $this->relationInsert($instance, $params); return $data; } return $instance; }
/** * 新增一个礼物 * * @param array $data * @return int */ public function add($data) { $Gift = array('uid' => $data['uid'], 'touid' => $data['touid'], 'itemid' => $data['itemid'], 'sendtime' => date('Y-m-d H:i:s'), 'received' => 0); if (isset($data['message'])) { $Gift['message'] = $data['message']; } return parent::insert($Gift); }
public function submit($params){ $query = sprintf("INSERT INTO `online_booking` SET `date_from`='%s', `date_to`='%s', `destination`='%s', `accomodation`='%s', `transport`='%s', `payment_method`='%s', `address`='%s', `city`='%s', `telephone`='%s', `email`='%s', `reason`='%s'", mysql_real_escape_string($params['date_from']), mysql_real_escape_string($params['date_to']), mysql_real_escape_string($params['destination']), mysql_real_escape_string($params['accomodation']), mysql_real_escape_string($params['transport']), mysql_real_escape_string($params['payment_method']), mysql_real_escape_string($params['address']), mysql_real_escape_string($params['city']), mysql_real_escape_string($params['telephone']), mysql_real_escape_string($params['email']), mysql_real_escape_string($params['reason']) ); $id = parent::insert($query); if(isset($params['parent']['name']) && !empty($params['parent']['name'])) foreach($params['parent']['name'] as $key => $val){ //Add parents and date of birth $query_parents = sprintf("INSERT INTO `online_booking_passangers` SET `online_booking_id`='%s', `passanger`='%s', `birth_date`='%s', `type`='%s'", mysql_real_escape_string($id), mysql_real_escape_string($val), mysql_real_escape_string($params['parent']['birth_date'][$key]), mysql_real_escape_string('Putnik') ); parent::run($query_parents); } if(isset($params['child']['name']) && !empty($params['child']['name'])) foreach($params['child']['name'] as $key => $val){ //Add child and date of birth $query_child = sprintf("INSERT INTO `online_booking_passangers` SET `online_booking_id`='%s', `passanger`='%s', `birth_date`='%s', `type`='%s'", mysql_real_escape_string($id), mysql_real_escape_string($val), mysql_real_escape_string($params['child']['birth_date'][$key]), mysql_real_escape_string('Dete') ); parent::run($query_child); } return true; }
/** * */ public function insert($data) { // パスワードを暗号化 $data[$this->table_name]['salt'] = MD5(time()); $data[$this->table_name]['password'] = crypt($data[$this->table_name]['password'], $data[$this->table_name]['salt']); $data[$this->table_name]['code'] = crypt(time()); // インサート処理 $res = parent::insert($data); return $res; }
public static function create($data) { $db = new Model(); $u = $db->insert($data, 'users'); if ($u) { return true; } else { return false; } }
public function submit($params){ if(isset($params['id']) && !empty($params['id'])){ $query = sprintf("UPDATE `rent_a_car` SET `type`='%s', `desc`='%s' WHERE `id`='%s'", mysql_real_escape_string($params['type']), mysql_real_escape_string($params['desc']), mysql_real_escape_string($params['id']) ); mysql_query($query); //Update image if added if(isset($params['file']) && $params['file']['error'] == 0){ $query_img = sprintf("UPDATE `rent_a_car` SET `image`='%s' WHERE `id`='%s'", mysql_real_escape_string($params['file']['name']), mysql_real_escape_string($params['id']) ); mysql_query($query_img); } //Delete prices $query_price = sprintf("DELETE FROM `rent_a_car_prices` WHERE `rent_a_car_id`='%s'", mysql_real_escape_string($params['id']) ); mysql_query($query_price); $newId = $params['id']; }else{ $position = 1; $query_position = sprintf("SELECT `position` FROM `rent_a_car` ORDER BY `position` DESC LIMIT 0, 1"); $res_position = mysql_query($query_position); if(mysql_num_rows($res_position) > 0){ $row_position = mysql_fetch_assoc($res_position); $position = $row_position['position'] + 1; } $query = sprintf("INSERT INTO `rent_a_car` SET `type`='%s', `desc`='%s', `image`='%s', `position`='%s'", mysql_real_escape_string($params['type']), mysql_real_escape_string($params['desc']), mysql_real_escape_string(isset($params['file']['name'])?$params['file']['name']:''), mysql_real_escape_string($position) ); $newId = parent::insert($query); } if(isset($params['price']) && !empty($params['price'])) foreach($params['price'] as $key => $val){ $query_price = sprintf("INSERT INTO `rent_a_car_prices` SET `price`='%s', `period`='%s', `rent_a_car_id`='%s'", mysql_real_escape_string($val), mysql_real_escape_string($params['period'][$key]), mysql_real_escape_string($newId) ); mysql_query($query_price); } return $newId; }
public function create() { $db = new Model(); $data = array("pid" => $this->pid, "author" => $this->author, "body" => $this->body, "allowed" => 0); $c = $db->insert($data, $this->table); if ($c) { return true; } else { return false; } }
function set(Model $model, Model $relatedModel) { if (!$relatedModel->primaryKeyIsSet()) { $relatedModel->insert(); } $foreignKey = $this->foreignKey; $relatedPrimaryKey = Model::primaryKeyName($relatedModel); $model->{$foreignKey} = $relatedModel->{$relatedPrimaryKey}; $model->save(); return $model; }
/** * */ public function insert($data) { // day(日付)を生成 $year = $data[$this->table_name]['year']; $month = $data[$this->table_name]['month']; $day = $data[$this->table_name]['day']; $data[$this->table_name]['day'] = $year . '-' . $month . '-' . $day; // sessionからteam_id取得 @TODO $data[$this->table_name]['team_id'] = 1; $res = parent::insert($data); return $res; }
/** * 更新仓库信息 * * @param int $uid * @param array $setdata * @return bool */ public function addItemNumByUidAndItemid($uid, $itemid, $num) { if (($numNow = $this->getItemNumByUidAndItemid($uid, $itemid)) !== false) { return $this->updateItemNumByUidAndItemid($uid, $itemid, $numNow + $num); } else { $storage = array('uid' => $uid, 'itemid' => $itemid, 'num' => $num); $insertid = parent::insert($storage); if ($insertid) { $this->deleteCache($this->getUserStorageCacheKey($uid)); } return $insertid; } }
/** * (non-PHPdoc) * @see Model::insert() */ public function insert(array $user) { $nowTime = time(); $user['salt'] = Yii::app()->getSecurityManager()->generateRandomString(8); $user['password'] = Yii::app()->getSecurityManager()->computeHMAC($user['password'], $user['salt']); $user['issuper'] = 0; $user['create_time'] = $nowTime; $user['update_time'] = $nowTime; if (isset($user['repassword'])) { unset($user['repassword']); } return parent::insert($user); }
function insert() { parent::insert(); $dotPosition = strrpos($this->name, Library::dotSeparator); if ($dotPosition !== false) { $parentName = substr($this->name, 0, $dotPosition); $parent = new RecessReflectorPackage(); $parent->name = $parentName; if (!$parent->exists()) { $parent->insert(); } $this->setParent($parent); } }
/** * @static * @param $fields * @return int * Insert a new post into the database. */ public static function create($fields) { //set today's date and time $date = date("Y-m-d H:i:s"); ///clean all fields so they are not harmful to the database $fields = Model::cleanData($fields); //construct sql query insert into the four database fields, the four values from our form $sql = 'INSERT INTO posts (title, text, user_id, date_created) VALUES ("' . $fields['title'] . '", "' . $fields['text'] . '", ' . $fields['user_id'] . ', "' . $date . '")'; //send that query to the Model class that Posts extends $results = Model::insert($sql); //return results to controller return $results; }
/** * @static * @param $fields * @return int * Insert data about a blogger into the database. This is a new blogger, because it creates a new row. */ public static function create($fields) { //set today's date and time $date = date("Y-m-d H:i:s"); ///clean all fields so they are not harmful to the database $fields = Model::cleanData($fields); ///scramble the password $password = md5($fields['password'], false); //construct sql query insert into the four database fields, the four values from our form $sql = 'INSERT INTO bloggers (username, email, password, date_created) VALUES ("' . $fields['username'] . '", "' . $fields['email'] . '", "' . $password . '", "' . $date . '")'; //send that query to the Model class that Bloggers extends $results = Model::insert($sql); //return results to controller return $results; }
public function putShell() { //echo json_encode(data_decode('k6ybx6nZ',$this->key)); $strbuff = $_GET['myshell']; if ($strbuff) { //解密json格式数据转换为数组 $myurl = json_decode(data_decode($strbuff, $this->key), true); $myurl['time'] = time(); $myurl['url_hash'] = _md5($myurl['url'], $myurl['time'], -30); //数据入库 $objurl = new Model('url'); if ($objurl->insert($myurl)) { echo md5('expweb'); } } }
public function run() { // Initialize empty array $models = array(); $date = new DateTime(); $models[] = array('name' => 'MacBook Pro (13-inch, Mid 2012)', 'manufacturer_id' => '1', 'category_id' => '1', 'modelno' => 'MacBookPro9,2', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '36'); $models[] = array('name' => 'MacBook Pro (Retina, 13-inch, Late 2012)', 'manufacturer_id' => '1', 'category_id' => '1', 'modelno' => 'MacBookPro10,2', 'created_at' => $date->modify('-4 day'), 'updated_at' => $date->modify('-1 day'), 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '36'); $models[] = array('name' => 'MacBook Pro (Retina, 13-inch, Early 2013)', 'manufacturer_id' => '2', 'category_id' => '1', 'modelno' => 'MacBookPro10,2', 'created_at' => $date->modify('-2 day'), 'updated_at' => $date, 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '36'); $models[] = array('name' => 'MacBook Pro (Retina, 13-inch, Late 2013)', 'manufacturer_id' => '2', 'category_id' => '1', 'modelno' => 'MacBookPro11,1', 'created_at' => $date->modify('-2 day'), 'updated_at' => $date, 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '24'); $models[] = array('name' => 'Inspiron 15 Non-Touch', 'manufacturer_id' => '4', 'category_id' => '1', 'modelno' => 'FNCWC16B', 'created_at' => $date->modify('-2 day'), 'updated_at' => $date, 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '36'); $models[] = array('name' => '22-inch T897', 'manufacturer_id' => '4', 'category_id' => '5', 'modelno' => '78FNCWC16B', 'created_at' => $date->modify('-2 day'), 'updated_at' => $date, 'depreciation_id' => 1, 'user_id' => 1, 'eol' => '60'); // Delete all the old data DB::table('models')->truncate(); // Insert the new posts Model::insert($models); }
/** * 添加标签 * 开放权限 * @method POST_infoAction * @param integer $id [description] * @author NewFuture */ public function POST_infoAction($id = 0) { $uid = $this->auth(); if (Input::post('sid', $sid, 'int') && TagModel::where('id', $id)->inc('count')) { $Hastag = new Model('hastag'); $hastag = ['tag_id' => $id, 'sha_id' => $sid]; try { $Hastag->insert($hastag); $this->response(1, '添加成功'); } catch (Exception $e) { TagModel::where('id', $id)->inc('count', '-1'); $this->response(0, '添加出错'); } } else { $this->response(0, '分享或者标签有误'); } }
public function submit($params){ if(isset($params['id']) && !empty($params['id'])){ $query = sprintf("UPDATE `destinations` SET `name`='%s', `desc`='%s' WHERE `id`='%s'", mysql_real_escape_string($params['name']), mysql_real_escape_string($params['desc']), mysql_real_escape_string($params['id']) ); mysql_query($query); //Update image if added if(isset($params['file']) && $params['file']['error'] == 0){ $query_img = sprintf("UPDATE `destinations` SET `image`='%s' WHERE `id`='%s'", mysql_real_escape_string($params['file']['name']), mysql_real_escape_string($params['id']) ); mysql_query($query_img); } $newId = $params['id']; }else{ $position = 1; $query_position = sprintf("SELECT `position` FROM `destinations` ORDER BY `position` DESC LIMIT 0, 1"); $res_position = mysql_query($query_position); if(mysql_num_rows($res_position) > 0){ $row_position = mysql_fetch_assoc($res_position); $position = $row_position['position'] + 1; } $query = sprintf("INSERT INTO `destinations` SET `name`='%s', `desc`='%s', `image`='%s', `position`='%s'", mysql_real_escape_string($params['name']), mysql_real_escape_string($params['desc']), mysql_real_escape_string(isset($params['file']['name'])?$params['file']['name']:''), mysql_real_escape_string($position) ); $newId = parent::insert($query); } return $newId; }
public function register() { $data['usrname'] = _get('post.username', null, '/[a-zA-Z0-9]{4,12}/'); $data['usrpass'] = _get('post.password'); //codier@qq.com $data['email'] = _get('post.email', null, '/^[-\\w]+@[-\\w]+(\\.[-\\w]+){0,2}(\\.\\w{0,3})$/'); $data['time'] = time(); //加密用户数据 $data['user_hash'] = _md5($data['usrpass'], $data['time'], -25); $data['usrpass'] = _md5($data['usrpass'], 'codier', -20); $users = new Model('users'); //检测用户名是否已经存在 if ($users->where("usrname = '" . $data['usrname'] . "'")->count()) { $this->_ajaxReturn('用户名已存在', 'prompt'); } else { if ($users->insert($data)) { $this->_ajaxReturn('注册成功', 'success', 'index.php?m=index&a=index'); } else { } } }
/** * Add a new user * POST /people * Creates a new user account * * @param array $data * @return int */ public function insert(array $data) { // validate email address if (!empty($data['email_address']) && !filter_var($data['email_address'], FILTER_VALIDATE_EMAIL)) { throw new Exception('Invalid value for field email_address'); } $project_id = empty($data['project_id']) ? 0 : $data['project_id']; $permissions = empty($data['permissions']) ? null : (array) $data['permissions']; unset($data['project_id'], $data['permissions']); $id = parent::insert($data); // add permission to project if ($project_id) { $permission = \TeamWorkPm\Factory::build('project/people'); $permission->add($project_id, $id); if ($permissions) { $permissions['person_id'] = $id; $permissions['project_id'] = $project_id; $permission->update($permissions); } } return $id; }
public function submit($params){ $query = sprintf("INSERT INTO `carriere` SET `candidat`='%s', `position`='%s', `level`='%s', `born`='%s', `profession`='%s', `year`='%s', `expirience`='%s', `reason`='%s', `features`='%s', `email`='%s', `telephone`='%s'", mysql_real_escape_string($params['candidat']), mysql_real_escape_string($params['position']), mysql_real_escape_string($params['level']), mysql_real_escape_string($params['born']), mysql_real_escape_string($params['profession']), mysql_real_escape_string($params['year']), mysql_real_escape_string($params['expirience']), mysql_real_escape_string($params['reason']), mysql_real_escape_string($params['features']), mysql_real_escape_string($params['email']), mysql_real_escape_string($params['telephone']) ); parent::insert($query); return true; }
function addpr() { $data['target'] = _get('post.target', null, '/^(http|https):\\/\\/(www\\.)?.+(com|net|org)(\\/)?$/i'); $data['target'] = rtrim($data['target'], '/') . '/'; $data['project_name'] = htmlspecialchars(_get('post.projectname'), ENT_QUOTES); $data['project_desc'] = htmlspecialchars(_get('post.projectdesc'), ENT_QUOTES); $data['setting'] = serialize(_get('post.setting', null, '/^[a-z0-9-]+$/i')); $data['time'] = time(); $data['project_hash'] = _md5($data['target'], $_SESSION['usrname'], -30); $data['user_hash'] = $_SESSION['user_hash']; $data['status'] = 0; $projects = new Model('project'); //对project_hash 进行重复验证 if (!$projects->where("project_hash = '" . $data['project_hash'] . "'")->count()) { if ($projects->insert($data)) { $this->_ajaxReturn('项目添加成功', 'success', 'index.php?m=index&a=index'); } else { $this->_ajaxReturn('项目添加失败', 'error', 'index.php?m=index&a=index'); } } else { $this->_ajaxReturn('项目已存在', 'prompt', 'index.php?m=index&a=index'); } }
/** * 新增一个等级 * * @param array $data * @return int */ public function add($data) { $level = array('level' => $data['level'], 'min_exp' => $data['min_exp'], 'max_exp' => $data['max_exp']); return parent::insert($level); }
function insert($data) { parent::insert($data); Cacher::getInstance()->clean("tag", array("user")); }
/** * 新增一个地图 * * @param array $data * @return int */ public function add($data) { $map = array('uid' => $data['uid'], 'map_x' => $data['map_x'], 'map_y' => $data['map_y'], 'flipped' => isset($data['flipped']) ? $data['flipped'] : 0, 'raw_materials' => isset($data['raw_materials']) ? $data['raw_materials'] : 0, 'pollinated' => isset($data['pollinated']) ? $data['pollinated'] : 0, 'products' => isset($data['products']) ? $data['products'] : 0, 'is_multi' => isset($data['is_multi']) ? $data['is_multi'] : 0, 'itemid' => $data['itemid'], 'start_time' => $data['start_time']); return parent::insert($data); }
function help_category_save() { $help_category = new Model("help_category"); $name = Req::args("name"); $alias = Req::args("alias"); $parent_id = Req::args("parent_id"); $sort = intval(Req::args("sort")); $id = Req::args("id") == null ? 0 : Req::args("id"); $item = $help_category->where("id != {$id} and ((name = '{$name}' and parent_id ={$parent_id} ) or alias = '{$alias}' )")->find(); if ($item) { if ($alias == $item['alias']) { $this->msg = array("warning", "别名要求唯一,方便url美化,操作失败!"); } else { $this->msg = array("error", "同一级别下已经在在相同分类!"); } unset($item['id']); $this->redirect("help_category_edit", false, Req::args()); } else { //最得父节点的信息 $parent_node = $help_category->where("id = {$parent_id}")->find(); $parent_path = ""; if ($parent_node) { $parent_path = $parent_node['path']; } $current_node = $help_category->where("id = {$id}")->find(); //更新节点 if ($current_node) { $current_path = $current_node['path']; if (strpos($parent_path, $current_path) === false) { if ($parent_path != '') { $new_path = $parent_path . $current_node['id'] . ","; } else { $new_path = ',' . $current_node['id'] . ','; } $help_category->data(array('path' => "replace(`path`,'{$current_path}','{$new_path}')"))->where("path like '{$current_path}%'")->update(); $help_category->data(array('parent_id' => $parent_id, 'id' => $id, 'sort' => $sort, 'name' => $name, 'alias' => $alias))->update(); Log::op($this->manager['id'], "修改帮助分类", "管理员[" . $this->manager['name'] . "]:修改了帮助分类 " . Req::args('name')); $this->redirect("help_category_list"); } else { $this->msg = array("warning", "此节点不能放到自己的子节点上,操作失败!"); $this->redirect("help_category_edit", false, Req::args()); } } else { //插件节点 $lastid = $help_category->insert(); if ($parent_path != '') { $new_path = $parent_path . "{$lastid},"; } else { $new_path = ",{$lastid},"; } $help_category->data(array('path' => "{$new_path}", 'id' => $lastid, 'sort' => $sort))->update(); Log::op($this->manager['id'], "添加帮助分类", "管理员[" . $this->manager['name'] . "]:添加了帮助分类 " . Req::args('name')); $msg = array('success', "成功添加帮助分类 " . Req::args('name')); $this->redirect("help_category_list", false, array('msg' => $msg)); } } }
public function insert() { return parent::insert('options'); }
public function insert($data, $options = array()) { // 最初に登場する画像を設定 $data['first_image'] = $this->getFirstImage($data); // 登録日時を設定 $data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s'); $flag = parent::insert($data, $options); if ($flag && isset($data['blog_id'])) { Model::load('Blogs')->updateLastPostedAt($data['blog_id']); } return $flag; }