本文整理汇总了PHP中Model::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::insert方法的具体用法?PHP Model::insert怎么用?PHP Model::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @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);
}
示例2: addTo
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;
}
示例3: insert
public function insert(array $params = [])
{
if ($instance = parent::insert($params)) {
$data = $this->relationInsert($instance, $params);
return $data;
}
return $instance;
}
示例4: add
/**
* 新增一个礼物
*
* @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);
}
示例5: submit
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;
}
示例6: insert
/**
*
*/
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;
}
示例7: create
public static function create($data)
{
$db = new Model();
$u = $db->insert($data, 'users');
if ($u) {
return true;
} else {
return false;
}
}
示例8: submit
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;
}
示例9: create
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;
}
}
示例10: set
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;
}
示例11: insert
/**
*
*/
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;
}
示例12: addItemNumByUidAndItemid
/**
* 更新仓库信息
*
* @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;
}
}
示例13: insert
/**
* (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);
}
示例14: insert
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);
}
}
示例15: create
/**
* @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;
}