简体   繁体   中英

Get the last inserted row's primary key in php

i'm working on php and i want insert something in my sql data-base and get the row's inserted primary key in the same time so i've done something like this to insert

$SQL = "INSERT INTO `saisie` (`sid`, `reference`) VALUES (NULL,?)";
$set = $db->prepare($SQL);
$result = $set->execute(array($refCode));

but i don't know what to do to get the sid of that inserted row

you could use this to get the last inserted ID

$id = mysqli_insert_id($db); or
$id = $db->mysqli_insert_id(); or
$id = $db->lastInsertId();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM