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


PHP DboSource::lastInsertId方法代碼示例

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


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

示例1: setupAdmin

 /**
  * Setup the admin user.
  *
  * @return bool
  */
 public function setupAdmin()
 {
     $answer = strtoupper($this->in('<question>Would you like to [c]reate a new user, or use an [e]xisting user?</question>', array('C', 'E')));
     $userMap = Configure::read('Forum.userMap');
     $statusMap = Configure::read('Forum.statusMap');
     // New User
     if ($answer === 'C') {
         $this->install['username'] = $this->_newUser('username');
         $this->install['password'] = $this->_newUser('password');
         $this->install['email'] = $this->_newUser('email');
         $result = $this->db->execute(sprintf("INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`) VALUES (%s, %s, %s, %s);", $this->install['table'], $userMap['username'], $userMap['password'], $userMap['email'], $userMap['status'], $this->db->value(Sanitize::clean($this->install['username'])), $this->db->value(Security::hash($this->install['password'], null, true)), $this->db->value($this->install['email']), $this->db->value($statusMap['active'])));
         if ($result) {
             $this->install['user_id'] = $this->db->lastInsertId();
         } else {
             $this->out('<error>An error has occurred while creating the user</error>');
             return $this->setupAdmin();
         }
         // Old User
     } else {
         if ($answer === 'E') {
             $this->install['user_id'] = $this->_oldUser();
             // Redo
         } else {
             return $this->setupAdmin();
         }
     }
     // Give ACL
     $result = ClassRegistry::init('Forum.Access')->add(array('parent_id' => $this->install['acl_admin'], 'foreign_key' => $this->install['user_id']));
     if (!$result) {
         $this->out('<error>An error occurred while granting administrator access</error>');
         return $this->setupAdmin();
     }
     return true;
 }
開發者ID:alescx,項目名稱:forum,代碼行數:39,代碼來源:InstallShell.php


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