我使用以下选项初始化类:
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
然后我表现得像这样
$this->sql = trim($sql);
$this->bind = $this->cleanup($bind);
$this->error = "";
try {
$pdostmt = $this->prepare($this->sql);
if($pdostmt->execute($this->bind) !== false) {
if(preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
elseif(preg_match("/^(" . implode("|", array("delete", "update")) . ") /i", $this->sql))
return $pdostmt->rowCount();
elseif(preg_match("/^(" . implode("|", array("insert")) . ") /i", $this->sql))
return $pdostmt->lastInsertId();
}
那是因为在INSERT之后我需要返回最后一个插入的id。 但我被告知lastInsertId()不是一个函数。 所以它不起作用。
任何想法?也许错误的选择? 谢谢