mysql id of inserted row
-- For mysql
INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
SELECT LAST_INSERT_ID();
mysql id of inserted row
-- For mysql
INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
SELECT LAST_INSERT_ID();
get id of record created php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "New record created successfully. Last inserted ID is: " . $last_id;
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
mysql get last insert id
SELECT MAX(id) AS last_id FROM users
-- last_id --
-- 33 --
mysql get last inserted id
-- To get the last inserted auto-increment row ID: --
SELECT LAST_INSERT_ID( optional_expression )
-- If you have just inserted it using a command in C# use: --
int lastId = (Int32)yourCommand.LastInsertedId;
find last id
//laravel controller
$newOrder = new Order();
...
...
$newOrder->save();
$last_id = $newOrder->id;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us