當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connection::getInsertID方法代碼示例

本文整理匯總了PHP中Connection::getInsertID方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::getInsertID方法的具體用法?PHP Connection::getInsertID怎麽用?PHP Connection::getInsertID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Connection的用法示例。


在下文中一共展示了Connection::getInsertID方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: insert

 /**
  * @param array $_value
  * @return string
  */
 public function insert(array $_value)
 {
     /* ## LOGGER ## */
     if (isset($this->logger)) {
         $this->logger->DEBUG('insert');
     }
     if (empty($_value)) {
         throw new UndefinedException('null');
     }
     // HANDLING MIT NULL WERTEN
     // AUCH IN UPDATE
     $data = '';
     $values = '';
     foreach ($_value as $key => $value) {
         $data .= ',`' . $this->connection->escape($key) . '`';
         if ($value == 'NULL') {
             $values .= ',NULL';
         } else {
             $values .= ',\'' . $this->connection->escape($value) . '\'';
         }
     }
     $data = substr($data, 1);
     $values = substr($values, 1);
     $table = $this->connection->escape($this->table);
     $primary = $this->connection->escape($this->primary);
     if (array_key_exists($primary, $_value) || empty($primary)) {
         $sql = 'INSERT INTO `' . $table . '` (' . $data . ') VALUES (' . $values . ');';
     } else {
         $sql = 'INSERT INTO `' . $table . '` (`' . $primary . '`, ' . $data . ') VALUES (NULL, ' . $values . ');';
     }
     $result = $this->connection->send($sql);
     // bedingungen prüfen
     // undefined row field table ..
     // fehlermeldungen verschönern
     if ($this->connection->getAffectedRows() <= 0) {
         throw new SQLStatementException('invalid statement ' . $sql);
     }
     if (array_key_exists($primary, $_value)) {
         return $_value[$this->primary];
     } else {
         if (empty($primary)) {
             return 0;
         } else {
             return $this->connection->getInsertID();
         }
     }
 }
開發者ID:keil,項目名稱:phpDBI-MySQL-Database-Interface-,代碼行數:51,代碼來源:Table.class.php

示例2: save

 public function save()
 {
     $oCon = new Connection();
     if ($this->iPostID == 0) {
         $sSQL = "INSERT INTO tbposts (PostContent, TopicID, MemberID) VALUES (\n            '" . $this->sPostContent . "',\n            '" . $this->iTopicID . "',\n            '" . $this->iMemberID . "')";
         $bResult = $oCon->query($sSQL);
         if ($bResult == true) {
             $this->iPostID = $oCon->getInsertID();
         } else {
             die($sSQL . " did not run");
         }
     } else {
         $sSQL = 'UPDATE tbposts SET Active = ' . $this->iActive . ' WHERE PostID=' . $this->iPostID;
         $bResult = $oCon->query($sSQL);
     }
     $oCon->close();
 }
開發者ID:Professorsaurus,項目名稱:Assignment-3-Final-Demo,代碼行數:17,代碼來源:posts.php

示例3: save

 public function save()
 {
     $oCon = new Connection();
     if ($this->iCategoryID == 0) {
         $sSQL = 'INSERT INTO tbcategory (CategoryName, CategoryDesc)
         VALUES(
             "' . $this->sCategoryName . '",
             "' . $this->sCategoryDesc . '")';
         $bResult = $oCon->query($sSQL);
         if ($bResult == true) {
             $this->iCategoryID = $oCon->getInsertID();
         } else {
             die($sSQL . " did not run");
         }
     } else {
         $sSQL = 'UPDATE tbcategory SET Active = ' . $this->iActive . ' WHERE CategoryID=' . $this->iCategoryID;
         $bResult = $oCon->query($sSQL);
     }
     $oCon->close();
 }
開發者ID:Professorsaurus,項目名稱:Assignment-3-Final-Demo,代碼行數:20,代碼來源:categories.php

示例4: save

 public function save()
 {
     $oCon = new Connection();
     if ($this->iCustomerID == 0) {
         $sSQL = "INSERT INTO tbcustomer (Name, Address, Phone, Email, Password) \n\t\t\t\tVALUES ('" . $this->sName . "', '" . $this->sAddress . "', '" . $this->sPhone . "', '" . $this->sEmail . "', '" . $this->sPassword . "')";
         $bResult = $oCon->query($sSQL);
         if ($bResult == true) {
             $this->iCustomerID = $oCon->getInsertID();
         } else {
             die($sSQL . " Did not run");
         }
     } else {
         $sSQL = "UPDATE tbcustomer \n\t\t\t\t\tSET Name = '" . $this->sName . "',\n\t\t\t\t\t \tAddress = '" . $this->sAddress . "',\n\t\t\t\t\t \tPhone = '" . $this->sPhone . "',\n\t\t\t\t\t \tEmail = '" . $this->sEmail . "',\n\t\t\t\t\t \tPassword = '" . $this->sPassword . "'\n\t\t\t\t\t \tWHERE CustomerID = " . $this->iCustomerID;
         $bResult = $oCon->query($sSQL);
         if ($bResult == false) {
             die($sSQL . " Did not run");
         }
     }
     $oCon->close();
 }
開發者ID:wasim01,項目名稱:theRecordBreakers,代碼行數:20,代碼來源:customer.php

示例5: save

 public function save()
 {
     $oCon = new Connection();
     if ($this->iMemberID == 0) {
         $sSQL = "INSERT INTO tbmember\n            (MemberName, MemberPassword, MemberEmail) VALUES             ('" . $this->sMemberName . "',\n                    '" . $this->sMemberPassword . "',\n                    '" . $this->sMemberEmail . "')";
         $bResult = $oCon->query($sSQL);
         if ($bResult == true) {
             $this->iMemberID = $oCon->getInsertID();
         } else {
             die($sSQL . " did not run");
         }
     } else {
         $sSQL = "UPDATE tbmember SET MemberName = '" . $this->sMemberName . "'WHERE MemberID = " . $this->iMemberID;
         $bResult = $oCon->query($sSQL);
         if (bResult == false) {
             die($sSQL . " did not run");
         }
     }
     $oCon->close();
 }
開發者ID:Professorsaurus,項目名稱:Assignment-3-Final-Demo,代碼行數:20,代碼來源:member.php

示例6: save

 public function save()
 {
     $oCon = new Connection();
     if ($this->iTopicID == 0) {
         $sSQL = 'INSERT INTO tbtopics (TopicSubject, TopicDesc, CategoryID, MemberID)
         VALUES(
             "' . $this->sTopicSubject . '",
             "' . $this->sTopicDesc . '",
             "' . $this->iCategoryID . '",
             "' . $this->iMemberID . '")';
         $bResult = $oCon->query($sSQL);
         if ($bResult == true) {
             $this->iTopicID = $oCon->getInsertID();
         } else {
             die($sSQL . " did not run");
         }
     } else {
         $sSQL = 'UPDATE tbtopics SET Active = ' . $this->iActive . ' WHERE TopicID=' . $this->iTopicID;
         $bResult = $oCon->query($sSQL);
     }
     $oCon->close();
 }
開發者ID:Professorsaurus,項目名稱:Assignment-3-Final-Demo,代碼行數:22,代碼來源:topics.php


注:本文中的Connection::getInsertID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。