I am following mvc structure in PHP and I want to retrieve last inserted row ID.
I have created following sql code:
$sql = \"INSERT
you can try the following -
$query = "INSERT INTO song (artist, track, link) VALUES (:artist, :track, :link)";
$stmt = $pdo->prepare($query);
$params = array(
"artist" => $artist,
"track" => $track,
"link" => $link,
);
$data = $stmt->execute($params);
$insert_id = $pdo->lastInsertId();
You're almost there.
If you look at the manual page for lastInsertId, it's called on the database handle - you're currently calling it on the statement.
You just need to call:
$this->db->lastInsertId();