I am not able to get the lastinsertid value using $db->lastInsertId(); or $db->lastInsertId('fid');
$stmt = $db->stmt_init();
$sql = "INSERT INTO ch_files_details (name,extension,size,parent) VALUES (?,?,?,?)";
$stmt = $db->prepare($sql) or die($db->error());
$stmt->bind_param('ssii', $filename, $extension, $filesize, $parent);
$stmt->execute();
$fid = $db->lastInsertId();
Something missing or wrong there?
I am able to insert into the table but simply cannot get the last inserted id.
Table Definition:
`ch_files_details` (
`fid` bigint(20) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`extension` text NOT NULL,
`size` bigint(20) NOT NULL,
`parent` bigint(20) NOT NULL,
PRIMARY KEY (`fid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;
PDO::lastInsertIddoes not work here, because you are not using PDO. The code you have above is MySQLi code, not PDO. Usemysqli::$insert_id.Review the MySQLi manual for full details. At some point you ended up in the wrong documentation set.