当前位置: 首页>>代码示例>>PHP>>正文


PHP Context::getInsertId方法代码示例

本文整理汇总了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;
 }
开发者ID:stanley89,项目名称:piratskelisty,代码行数:29,代码来源:Clanky.php

示例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());
     }
 }
开发者ID:stanley89,项目名称:piratskelisty,代码行数:12,代码来源:Upload.php

示例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);
         }
     }
 }
开发者ID:amertak,项目名称:Fractions,代码行数:14,代码来源:BasePresenter.php

示例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
         }
     }
 }
开发者ID:jandoubek,项目名称:fjfi-pvs-inzeraty,代码行数:19,代码来源:InzeratManager.php

示例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');
 }
开发者ID:spaze,项目名称:cotel,代码行数:15,代码来源:HomepagePresenter.php

示例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;
 }
开发者ID:jave007,项目名称:test,代码行数:50,代码来源:Selection.php

示例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;
     }
 }
开发者ID:Zarganwar,项目名称:orm,代码行数:36,代码来源:NetteMapper.php


注:本文中的Nette\Database\Context::getInsertId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。