I tried but I can't get insert_id from the function. I have made a class call functions but I don't understand how can I get it. See below code.
class DatabaseConnection {
protected $pdo;
public function __construct() {
try {
$this->pdo = new PDO('mysql:host=localhost;dbname=xxx', 'root', '');
} catch(PDOException $e) {
exit('Database error');
}
}
}
class Invoice extends DatabaseConnection {
public function order($rename, $location) {
$query = $this->pdo->prepare("INSERT INTO orderlist (re_name, location) VALUES (?, ?)");
$query -> execute(array($rename, $location));
}
$user = new Invoice();
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$rename = $_POST['re_name'];
$location = $_POST['location'];
$insertOrder = $user->order($rename, $location); // call the function here
$insertid = ____ // I want to get id using insert_id in here see blank space.
}
Data is inserted successfully but how can I get id which I insert data recently. help me.