Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 724305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:12:25+00:00 2026-05-14T06:12:25+00:00

Both the MySQLi and MySQLi_STMT classes have an $insert_id property. If I am connected

  • 0

Both the MySQLi and MySQLi_STMT classes have an $insert_id property.

If I am connected to my database using a MySQLi object (say $db), and then I perform an INSERT with a MySQLi_STMT object (say $stmt), to get the id of the last INSERT, should I use:

$last_id = $db->insert_id;

or

$last_id = $stmt->insert_id;

Or would they be the same, in which case it doesn’t matter?

I thought this might be a quick answer for someone, and save me the time of writing the test code to check it.

Thanks in advance as always.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:12:26+00:00Added an answer on May 14, 2026 at 6:12 am

    I would assume that both are the same, if read at the same time.

    However if you execute another INSERT statement, the $db->insert_id might change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a database wrapper both in mysql and mysqli . To get data
I'm running two queries in my script room.php . Both are using MySQLi prepared
I am implementing a database application and I will use both JavaDB and MySQL
I am using the following code to update my mysql table where both moving50
OK so I am using OOPHP to communicate between Flash Builder and MYSQL both
I have a database table which contains an unsigned integer field to store the
I use mysqli extension and bind the result to an object: class Item {
Lets say I have two separate databases, X and Y, on the same physical
I'm using PDO and trying to make my application support both MySQL and SQLite,
Say one were looking at transitioning a codebase from using the basic PHP mysql_*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.