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


PHP DataBase::lastInsertId方法代码示例

本文整理汇总了PHP中DataBase::lastInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP DataBase::lastInsertId方法的具体用法?PHP DataBase::lastInsertId怎么用?PHP DataBase::lastInsertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBase的用法示例。


在下文中一共展示了DataBase::lastInsertId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveToDB

 public function saveToDB($poiId, $componentId, $stageRating)
 {
     global $secKeys;
     $now = date("Y-m-d H:i:s");
     try {
         DataBase::connect('localhost', $secKeys->cakeVars->{'dbUsr'}, $secKeys->cakeVars->{'dbPw'}, $secKeys->cakeVars->{'dbCake'});
         $sql = "INSERT INTO stages (component_id, poi_id, created, modified, rating) VALUES (:component_id, :poi_id, :tstamp, :tstamp, :rating)";
         $para = array('component_id' => $componentId, 'poi_id' => $poiId, 'tstamp' => $now, 'rating' => $stageRating);
         DataBase::fire($sql, $para);
         $this->savedStagesCount = DataBase::lastInsertId();
         DataBase::close();
     } catch (Exception $e) {
         die('Fehler bei .... Fehler: ' . $e->getMessage());
     }
 }
开发者ID:vsur,项目名称:foodemapp,代码行数:15,代码来源:rand_stages.php

示例2: saveToDB

 public function saveToDB($filterdQueryData)
 {
     global $secKeys;
     ControlFunctions::forDebug($filterdQueryData, "Gefilterte Pois");
     // for ($i = 0; $i < 5; $i++) {
     for ($i = 0; $i < count($filterdQueryData); $i++) {
         $now = date("Y-m-d H:i:s");
         try {
             DataBase::connect('localhost', $secKeys->cakeVars->{'dbUsr'}, $secKeys->cakeVars->{'dbPw'}, $secKeys->cakeVars->{'dbCake'});
             $sql = "INSERT INTO pois (created, modified, name, lat, lng, google_place, icon, rating, vicinity) VALUES (:tstamp, :tstamp, :name, :lat, :lng, :google_place, :icon, :rating, :vicinity)";
             $para = array('tstamp' => $now, 'name' => $filterdQueryData[$i]->name, 'lat' => $filterdQueryData[$i]->geometry->location->lat, 'lng' => $filterdQueryData[$i]->geometry->location->lng, 'google_place' => $filterdQueryData[$i]->place_id, 'icon' => $filterdQueryData[$i]->icon, 'rating' => isset($filterdQueryData[$i]->rating) ? $filterdQueryData[$i]->rating : null, 'vicinity' => $filterdQueryData[$i]->vicinity);
             DataBase::fire($sql, $para);
             $lastPoisId = DataBase::lastInsertId();
             echo ControlFunctions::tagIt("h1", "Letzter Eintrag: " . $lastPoisId);
             foreach ($filterdQueryData[$i]->types as $tag) {
                 $tagId = null;
                 // Check if tag is already present
                 $sql = "SELECT EXISTS(SELECT 1 FROM tags WHERE title LIKE '%" . $tag . "%')";
                 $rows = DataBase::fire($sql);
                 $tagPresent = current(current($rows)) == "1" ? true : false;
                 ControlFunctions::forDebug($rows, "Ausgabe für Tag {$tag}");
                 echo $tagPresent ? "Wert für {$tag} ist: vorhanden" : "Wert für {$tag} ist: Nicht existent!";
                 if ($tagPresent) {
                     $sql = "SELECT id FROM tags WHERE title LIKE '%" . $tag . "%'";
                     $rows = DataBase::fire($sql);
                     $tagId = current(current($rows));
                     ControlFunctions::forDebug($rows, "Ausgabe für Tag {$tag}, tag ID: ");
                     echo ControlFunctions::tagIt("h1", "{$tag} ID: {$tagId}");
                 } else {
                     // Paste Tag
                     $sql = "INSERT INTO tags (title, created, modified) VALUES (:title, :tstamp, :tstamp)";
                     $para = array('title' => $tag, 'tstamp' => $now);
                     DataBase::fire($sql, $para);
                     // Save ID
                     $tagId = DataBase::lastInsertId();
                 }
                 // Paste Relation
                 $sql = "INSERT INTO pois_tags (poi_id, tag_id) VALUES (:poi_id, :tag_id)";
                 $para = array('poi_id' => $lastPoisId, 'tag_id' => $tagId);
                 DataBase::fire($sql, $para);
                 echo ControlFunctions::tagIt("h1", "Letzter Eintrag: " . DataBase::lastInsertId());
             }
             DataBase::close();
         } catch (Exception $e) {
             die('Fehler bei .... Fehler: ' . $e->getMessage());
         }
     }
 }
开发者ID:vsur,项目名称:foodemapp,代码行数:48,代码来源:save_data.php


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