8

How can I get the insert_id of the last record using mysqli prepare statement, for example following?

$stmt = $this->mysqli->prepare("INSERT INTO test (name) values (?)")
$stmt->bind_param('s', $name);
$stmt->execute();
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ajay
  • 1,107
  • 2
  • 13
  • 12

2 Answers2

11

$new_id = $this->mysqli->insert_id; (after $stmt->execute())

a1ex07
  • 36,826
  • 12
  • 90
  • 103
2

mysqli->insert_id

jspcal
  • 50,847
  • 7
  • 72
  • 76