本文整理汇总了PHP中Nette\Database\Context::getInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::getInsertId方法的具体用法?PHP Context::getInsertId怎么用?PHP Context::getInsertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Context
的用法示例。
在下文中一共展示了Context::getInsertId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add($vals)
{
$arr = array("titulek" => $vals['titulek'], "autor" => $vals["autor"], "kategorie_id" => $vals['kategorie_id'], "obrazek_id" => $vals['obrazek_id']);
if (!empty($vals['skupina'])) {
$arr['skupina'] = $vals['skupina'];
}
if (empty($vals['id'])) {
$this->database->query("INSERT INTO clanky ", $arr);
$id = $this->database->getInsertId();
} else {
$this->database->query("UPDATE clanky SET ", $arr, " WHERE id=?", $vals['id']);
$id = $vals['id'];
}
$arr = array("clanek_id" => $id, "perex" => $vals['perex'], "text" => $vals['text']);
$this->database->query("INSERT INTO clanky_revize", $arr);
$this->database->query("DELETE FROM stitky WHERE clanek_id=?;", $id);
$stitky = explode("\n", $vals['stitky_text']);
foreach ($stitky as $key => $stitek) {
if (empty($stitek)) {
continue;
}
$stitky[$key] = trim($stitek);
}
$stitky = array_unique($stitky);
foreach ($stitky as $stitek) {
$this->database->query("INSERT INTO stitky ", array("clanek_id" => $id, "stitek" => trim($stitek)));
}
return $id;
}
示例2: save
public function save($vals)
{
$arr = array('alt' => $vals['alt'], 'title' => $vals['title']);
if (!empty($vals['id'])) {
$this->database->query("UPDATE upload SET ", $arr, " WHERE id=?;", $vals['id']);
return $this->get($vals['id']);
} else {
$arr['extension'] = $vals['extension'];
$this->database->query("INSERT INTO upload ", $arr);
return $this->get($this->database->getInsertId());
}
}
示例3: ensureUser
private function ensureUser()
{
if (!$this->getUser()->isLoggedIn()) {
$this->database->query("INSERT INTO `users`", array("id" => null));
$us = $this->database->table('users')->where('id = ?', $this->database->getInsertId())->fetch();
$this->user->setExpiration('365 days', FALSE);
$this->user->login(new \Nette\Security\Identity($us->id, null, $us));
} else {
$us = $this->database->table('users')->where('id = ?', $this->user->getId())->fetch();
if ($us == null) {
$this->user->logout(true);
}
}
}
示例4: upload_photos
private function upload_photos($id_inzerat)
{
// upload new photos
foreach ($this->inzerat['photo'] as $image) {
// image into DB
$file_name = pathinfo($image->name, PATHINFO_FILENAME);
$ext = pathinfo($image->name, PATHINFO_EXTENSION);
$this->database->query('INSERT INTO image (id_poster, name, extension) VALUES (' . $id_inzerat . ',"' . $file_name . '","' . $ext . '")');
// image onto server
$id_image = $this->database->getInsertId();
$target_dir = 'images/';
$target_file = $target_dir . $id_image . '.' . $ext;
if (move_uploaded_file($image->getTemporaryFile(), $target_file)) {
// success
} else {
// error
}
}
}
示例5: submittedMedia
public function submittedMedia(\Cotel\Form\MediaForm $form)
{
$values = $form->getValues();
$tags = array_filter(preg_split('/\\s+/', $values->tags));
$this->database->beginTransaction();
$this->database->query('INSERT INTO urls', array('url' => $values->url, 'title' => $values->title, 'published' => new \DateTime($values->published), 'added' => new \DateTime('now')));
$urlId = $this->database->getInsertId();
$tagIds = array();
foreach ($tags as $tag) {
$this->database->query('INSERT INTO tags ? ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id)', array('tag' => $tag));
$this->database->query('INSERT INTO url_tags', ['url_id' => $urlId, 'tag_id' => $this->database->getInsertId()]);
}
$this->database->commit();
$this->redirect('this');
}
示例6: insert
/**
* Inserts row in a table.
* @param array|\Traversable|Selection array($column => $value)|\Traversable|Selection for INSERT ... SELECT
* @return IRow|int|bool Returns IRow or number of affected rows for Selection or table without primary key
*/
public function insert($data)
{
if ($data instanceof self) {
$return = $this->context->queryArgs($this->sqlBuilder->buildInsertQuery() . ' ' . $data->getSql(), $data->getSqlBuilder()->getParameters());
} else {
if ($data instanceof \Traversable) {
$data = iterator_to_array($data);
}
$return = $this->context->query($this->sqlBuilder->buildInsertQuery() . ' ?values', $data);
}
$this->loadRefCache();
if ($data instanceof self || $this->primary === NULL) {
unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]);
return $return->getRowCount();
}
$primarySequenceName = $this->getPrimarySequence();
$primaryKey = $this->context->getInsertId(!empty($primarySequenceName) ? $this->context->getConnection()->getSupplementalDriver()->delimite($primarySequenceName) : $primarySequenceName);
if ($primaryKey === FALSE) {
unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]);
return $return->getRowCount();
}
if (is_array($this->getPrimary())) {
$primaryKey = array();
foreach ((array) $this->getPrimary() as $key) {
if (!isset($data[$key])) {
return $data;
}
$primaryKey[$key] = $data[$key];
}
if (count($primaryKey) === 1) {
$primaryKey = reset($primaryKey);
}
}
$row = $this->createSelectionInstance()->select('*')->wherePrimary($primaryKey)->fetch();
if ($this->rows !== NULL) {
if ($signature = $row->getSignature(FALSE)) {
$this->rows[$signature] = $row;
$this->data[$signature] = $row;
} else {
$this->rows[] = $row;
$this->data[] = $row;
}
}
return $row;
}
示例7: persist
public function persist(IEntity $entity)
{
if (!$entity->isModified()) {
$entity->id;
}
$this->beginTransaction();
$id = $entity->getValue('id', TRUE);
$data = $entity->toArray(IEntity::TO_ARRAY_LOADED_RELATIONSHIP_AS_IS);
$storageProperties = $entity->getMetadata()->getStorageProperties();
foreach ($data as $key => $value) {
if (!in_array($key, $storageProperties, TRUE) || $value instanceof IRelationshipCollection) {
unset($data[$key]);
}
if ($value instanceof IEntity) {
$data[$key] = $value->id;
}
}
unset($data['id']);
$data = $this->getStorageReflection()->convertEntityToStorage($data);
if (!$entity->isPersisted()) {
$this->databaseContext->query('INSERT INTO ' . $this->getTableName() . ' ', $data);
if ($id) {
return $id;
} else {
return $this->databaseContext->getInsertId($this->databaseStructure->getPrimaryKeySequence($this->getTableName()));
}
} else {
$primary = [];
$id = (array) $id;
foreach ($this->getStorageReflection()->getStoragePrimaryKey() as $key) {
$primary[$key] = array_shift($id);
}
$this->databaseContext->query('UPDATE ' . $this->getTableName() . ' SET', $data, 'WHERE ?', $primary);
return $entity->id;
}
}