Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get last inserted id in php

Example (MySQLi Procedural)
$last_id = mysqli_insert_id($conn);
Comment

PHP MySQL Get Last Inserted ID

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
  $last_id = $conn->insert_id;
  echo "New record created successfully. Last inserted ID is: " . $last_id;
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: Replicating claims as headers is deprecated and will removed from v4.0. Please manually set the header if you need it replicated. 
Php :: PHP Casting Strings and Floats to Integers 
Php :: php convert unix time to date 
Php :: create session in wordpress 
Php :: laravel where column different 
Php :: php get time in milliseconds 
Php :: two digits after decimal point in php 
Php :: laravel generate slug 
Php :: set character set utf8 in pdo php 
Php :: re migrate laravel 
Php :: laravel get env variable 
Php :: increment single column laravel 
Php :: laravel collection filter 
Php :: unique value when two columns laravel migration 
Php :: Add Laravel .env variable to Vue component 
Php :: laravel grouping routes 
Php :: php var_dump pre 
Php :: nova resource title function 
Php :: laravel test specific class 
Php :: php retour à la ligne 
Php :: get the href in string regex php 
Php :: woocommerce my account url 
Php :: php explode by tab 
Php :: wp cli command activate plugin 
Php :: doctrine mongodb native query 
Php :: php datetime create 
Php :: laravel go back to previous page blade 
Php :: wordpress embed shortcode in php 
Php :: how to check if input is number only in php 
Php :: Google Dorks Using special search string to find vulnerable websites: 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =