我嘗試這樣做:無法獲得mysql_insert_id()工作
$cid = mysql_insert_id($this->result);
$this->result = "<div class='alert alert-success'>" . sprintf(_('Successfully added user id <b>%s</b> to the database.'), $cid) . "</div>";
但我只得到這個錯誤:
警告:mysql_insert_id():提供的參數不是一個有效的MySQL-Link的資源在
這是整個功能(I加入此$ CID = mysql_insert_id($這個 - >結果);希望檢索插入的數據的ID):
private function adduser() {
if (!empty($this->error)) return false;
$params = array(
':user_level' => parent::getOption('default-level'),
':name' => $this->name,
':email' => $this->email,
':username' => $this->username,
':password' => parent::hashPassword($this->password)
);
parent::query("INSERT INTO `login_users` (`user_level`, `name`, `email`, `username`, `password`)
VALUES (:user_level, :name, :email, :username, :password);", $params);
$shortcodes = array(
'site_address' => SITE_PATH,
'full_name' => $this->name,
'username' => $this->username,
'email' => $this->email,
'password' => $this->password
);
$subj = parent::getOption('email-add-user-subj');
$msg = parent::getOption('email-add-user-msg');
if(!parent::sendEmail($this->email, $subj, $msg, $shortcodes))
$this->error = _('ERROR. Mail not sent');
$cid = mysql_insert_id($this->result);
$this->result = "<div class='alert alert-success'>" . sprintf(_('Successfully added user <b>%s</b> to the database. Credentials sent to user.'), $cid) . "</div>";
}
這是連接到數據庫:
<?php
$host = "xxx";
$dbName = "xxx";
$dbUser = "xxx";
$dbPass = "xxx";
?>
我們需要看到幾前述線 - 尤其是在最後設置$這個 - >結果爲文本 – BugFinder
哪裏是你的查詢和指定的結果?請更新一些代碼行。 首先,使用'this-> result'作爲結果標識符,然後使用它來設置一個字符串似乎不正確。 – bartvanraaij