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

  • Home
  • SEARCH
  • 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 9247567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:45:40+00:00 2026-06-18T09:45:40+00:00

Suppose I run an insert statement like this: $sql = insert into tbl_features (feature_class,

  • 0

Suppose I run an insert statement like this:

        $sql = "insert into tbl_features (feature_class, feature_name, description) values (?, ?, ?)";
        $q = $pdo_conn->prepare($sql);
        $q->execute(array($_GET['new_feature_class'], $_GET['new_feature_name'], $_GET['new_description']));

I then want to retrieve the id of the row that was just inserted to use it in another table. I could use select max() but how can I be sure that nobody else has done an insert, thus giving both users the same max to try to cram into other tables? I’m happy to lock the entire table, the code gets run infrequently enough that it won’t make a noticeable difference. Maybe I’m being pedantic but I want to go to bed at night knowing my code is bulletproof.

  • 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-06-18T09:45:42+00:00Added an answer on June 18, 2026 at 9:45 am

    You can use lastInsertId to retrieve it: http://php.net/manual/en/pdo.lastinsertid.php.

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

Sidebar

Related Questions

I need to run this sql statement: INSERT INTO JSP_CONTROL (estado,hora_inicio,fecha,tipo) VALUES ('ACTUALIZANDO',to_char(sysdate, 'HH24:mi:SS'),sysdate,'uno');
Can someone help me with this SQL statement. I run it on the SQL
This query is supposed to run with ms access 2003 using SQL. the function
Suppose that I have a document like this, and I want to search for
So I'm writing a program that is suppose to run forever (client server stuff)
I have a requirement such that my program is suppose to run for a
Suppose I want to run the following method foo() once every hour in Grails:
Suppose I ask the user do you want to run in 32bit mode or
Suppose I have this base class: struct Vehicle { //op stands for the operator
I need to insert into database which has two columns- ID PrimaryKey String ACCOUNT

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.