I initialize the class with these options:
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
Then i behave like this
$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();
}
that's because after an INSERT i need to return the last inserted id. but i've been told lastInsertId() is not a function. so it doesn't work.
any idea? maybe wrong options? thank you
It's in the PDO
object, not in a PDOStatement
.