当前位置: 首页>>代码示例>>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;未经允许,请勿转载。