Hi,
I am trying to insert some data into a MySQL database using PDO and then return the ID of the row added. The function is running correctly, data is being inserted correctly, and the first 'test' string is being returned correctly, however nothing is being returned for lastInsertID or the second 'test' string.
There is an ID column in the database that is AUTO_INCREMENT and Primary Key.
Any help appreciated.
public function insertNewCustomer($data){
$this->db->query("INSERT INTO Customers (First_Name, Surname, Email) VALUES (:firstname, :surname, :email)");
//Bind Data
$this->db->bind(':firstname', $data['firstname']);
$this->db->bind(':surname', $data['surname']);
$this->db->bind(':email', $data['email']);
//Execute
if($this->db->execute()){
echo 'test' ;
echo $this->db->lastInsertId();
echo 'test' ;
} else {
return false;
}
}