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


PHP ADODB_mysqli::Insert_ID方法代码示例

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


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

示例1: save

 /**
  * Saves an entity to database
  *
  * @return \Scalr\Server\History
  * @throws Exception
  */
 public function save()
 {
     $stmt = array();
     $bind = array();
     $idKey = 'id';
     $idValue = array();
     $cols = array();
     foreach ($this->_getFields() as $field) {
         $cols[$field] = $this->{$field};
     }
     if (array_key_exists($idKey, $cols)) {
         if ($cols[$idKey]) {
             $idValue[] = $cols[$idKey];
         }
         unset($cols[$idKey]);
     }
     foreach ($cols as $field => $value) {
         $stmt[] = "`" . Scalr::decamelize($field) . "` = ?";
         $bind[] = $value;
     }
     try {
         $stmt = (empty($idValue) ? "INSERT" : "UPDATE") . " `servers_history` SET " . join(", ", $stmt) . (!empty($idValue) ? " WHERE `" . Scalr::decamelize($idKey) . "` = ?" : "");
         $this->db->Execute($stmt, array_merge($bind, $idValue));
         if (empty($idValue)) {
             $this->{$idKey} = $this->db->Insert_ID();
         }
     } catch (Exception $e) {
         throw new Exception(sprintf("Cannot save server history record. Error: %s", $e->getMessage()), $e->getCode());
     }
     return $this;
 }
开发者ID:recipe,项目名称:scalr,代码行数:37,代码来源:History.php

示例2: save

 public function save($forceInsert = false)
 {
     $set = array();
     $bind = array();
     foreach ($this->dbPropertyMap as $field => $value) {
         $isArrayValue = is_array($value);
         if ($field == $this->dbPrimaryKey && !$forceInsert) {
             continue;
         }
         if ($isArrayValue && isset($value['createSql']) && (!$this->id || $forceInsert)) {
             $set[] = "`{$field}` = {$value['createSql']}";
             continue;
         }
         if ($isArrayValue && isset($value['updateSql']) && $this->id && !$forceInsert) {
             $set[] = "`{$field}` = {$value['updateSql']}";
             continue;
         }
         if ($isArrayValue && isset($value['update']) && $value['update'] == false) {
             continue;
         }
         $property = $isArrayValue ? $value['property'] : $value;
         $val = $this->{$property};
         if ($isArrayValue && isset($value['type'])) {
             switch ($value['type']) {
                 case 'bool':
                     $val = $val ? 1 : 0;
                     break;
                 case 'datetime':
                     $val = is_null($val) ? $val : date("Y-m-d H:m:s", $val);
                     break;
                 case 'serialize':
                     $val = serialize($val);
                     break;
             }
         }
         $set[] = "`{$field}` = ?";
         $bind[] = $val;
     }
     $set = implode(', ', $set);
     try {
         if ($this->id && !$forceInsert) {
             // Perform Update
             $bind[] = $this->id;
             $this->db->Execute("UPDATE {$this->dbTableName} SET {$set} WHERE id = ?", $bind);
         } else {
             // Perform Insert
             $this->db->Execute("INSERT INTO {$this->dbTableName} SET {$set}", $bind);
             if (!$this->id) {
                 $this->id = $this->db->Insert_ID();
             }
         }
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot save record. Error: %s"), $e->getMessage()), $e->getCode());
     }
     return $this;
 }
开发者ID:recipe,项目名称:scalr,代码行数:56,代码来源:Model.php

示例3: save

 public function save($update_system_records = false)
 {
     $row = $this->unBind();
     unset($row['id']);
     unset($row['dtlastmodified']);
     $this->db->BeginTrans();
     // Prepare SQL statement
     $set = array();
     $bind = array();
     foreach ($row as $field => $value) {
         $set[] = "`{$field}` = ?";
         $bind[] = $value;
     }
     $set = join(', ', $set);
     try {
         //Save zone;
         if ($this->id) {
             if ($update_system_records) {
                 $this->updateSystemRecords();
             }
             // Perform Update
             $bind[] = $this->id;
             $this->db->Execute("UPDATE dns_zones SET {$set}, `dtlastmodified` = NOW() WHERE id = ?", $bind);
             //TODO:
             if ($update_system_records) {
                 $this->db->Execute("UPDATE dns_zones SET status=?, `dtlastmodified` = NOW() WHERE id = ?", array($this->status, $this->id));
             }
         } else {
             // Perform Insert
             $this->db->Execute("INSERT INTO dns_zones SET {$set}", $bind);
             $this->id = $this->db->Insert_ID();
             if ($update_system_records) {
                 $this->updateSystemRecords();
                 $this->db->Execute("UPDATE dns_zones SET status=?, `dtlastmodified` = NOW() WHERE id = ?", array($this->status, $this->id));
             }
         }
         if ($this->updateRecords) {
             $this->db->Execute("DELETE FROM dns_zone_records WHERE zone_id=? AND issystem='0'", array($this->id));
             foreach ($this->records as $record) {
                 //UNIQUE KEY `zoneid` (`zone_id`,`type`(1),`value`,`name`)
                 $this->db->Execute("\n                        INSERT INTO dns_zone_records\n                        SET `zone_id` = ?,\n                            `type` = ?,\n                            `value` = ?,\n                            `name` = ?,\n                            `issystem` = '0',\n                            `ttl` = ?,\n                            `priority` = ?,\n                            `weight` = ?,\n                            `port` = ?\n                        ON DUPLICATE KEY UPDATE\n                            `issystem` = '0',\n                            `ttl` = ?,\n                            `priority` = ?,\n                            `weight` = ?,\n                            `port` = ?\n                    ", array($this->id, $record['type'], $record['value'], $record['name'], (int) $record['ttl'], (int) $record['priority'], (int) $record['weight'], (int) $record['port'], (int) $record['ttl'], (int) $record['priority'], (int) $record['weight'], (int) $record['port']));
             }
         }
     } catch (Exception $e) {
         $this->db->RollbackTrans();
         throw new Exception("Cannot save DBDNS zone. Error: " . $e->getMessage(), $e->getCode());
     }
     $this->db->CommitTrans();
     try {
         //$this->saveInPowerDns();
     } catch (Exception $e) {
         Logger::getLogger("DNS")->fatal("Unable to save data in PowerDNS db: {$e->getMessage()}");
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:54,代码来源:class.DBDNSZone.php

示例4: setUserRoles

 /**
  * Set roles for specified user for specified team.
  *
  * @param   int        $teamId       The identifier of the team
  * @param   int        $userId       The identifier of the user
  * @param   array      $accountRoles The list of the identifiers of the roles of account level
  * @param   int        $accountId    optional The identifier of the account
  */
 public function setUserRoles($teamId, $userId, $accountRoles, $accountId = null)
 {
     $accountId = intval($accountId);
     //Verify that team and user are from the same acount
     if (!empty($accountId)) {
         $check = $this->db->GetOne("\n                SELECT 1 FROM account_users WHERE id = ? AND account_id = ? LIMIT 1\n            ", array($userId, $accountId)) && $this->db->GetOne("\n                SELECT 1 FROM account_teams WHERE id = ? AND account_id = ? LIMIT 1\n            ", array($teamId, $accountId));
         if (!$check) {
             throw new Exception\AclException(sprintf('Cannot find the team "%d" or user "%d" in the account "%d"', $teamId, $userId, $accountId));
         }
     } else {
         //Retrieves identifier of the account
         $accountId = $this->db->GetOne("\n                SELECT u.account_id\n                FROM account_users u\n                JOIN account_teams t ON t.account_id = u.account_id\n                WHERE u.user_id = ? AND t.team_id = ?\n                LIMIT 1\n            ", array($userId, $accountId));
         if (!$accountId) {
             throw new Exception\AclException(sprintf('Cannot find the team "%d" or user "%d" in the account "%d"', $teamId, $userId, $accountId));
         }
     }
     $teamUserId = $this->db->GetOne("\n           SELECT tu.id\n           FROM `account_team_users` tu\n           WHERE tu.`team_id` = ? AND tu.`user_id` = ?\n           LIMIT 1\n        ", array($teamId, $userId));
     if (empty($teamUserId)) {
         $this->db->Execute("\n                INSERT IGNORE `account_team_users`\n                SET team_id = ?,\n                    user_id = ?\n            ", array($teamId, $userId));
         $teamUserId = $this->db->Insert_ID();
     } else {
         //Removes previous relations
         $this->db->Execute("\n                DELETE FROM `account_team_user_acls` WHERE account_team_user_id = ?\n            ", array($teamUserId));
     }
     if ($c = count($accountRoles)) {
         //Creates new relations
         $this->db->Execute("\n                INSERT IGNORE `account_team_user_acls` (account_team_user_id, account_role_id)\n                SELECT ?, r.account_role_id\n                FROM `acl_account_roles` r\n                WHERE r.account_id = ?\n                AND r.account_role_id IN (" . rtrim(str_repeat("?,", $c), ',') . ")\n            ", array_merge(array($teamUserId, $accountId), array_values($accountRoles)));
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:37,代码来源:Acl.php


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