Hi All,
I have a poblem with the Phalcon\Db insert method. I want to return the current inserted record's id. Is this possible?
public function createSession($clientId, $ownerType, $ownerId)
{
$this->db->insert(
$this->tables['oauth_sessions'],
[$clientId, $ownerType, $ownerId],
['client_id', 'owner_type', 'owner_id']
);
return $this->db->lastInsertId();
}
// Here is the lastInsertID function
function lastInsertId(){
$sql = 'SELECT CAST(SCOPE_IDENTITY() AS int) AS ID';
$this->db->fetchOne($sql, Db::FETCH_ASSOC);
return $id;
}
I use a custom mssql adapter to connect my SQLSRV database and it works fine but I cannot call a method ( SELECT SCOPE_IDENTITY() ) to return the inserted ID. It just returns null.
Please help.
Thanks!