本文整理匯總了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;
}