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 8633455
In Process

The Archive Base Latest Questions

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

I have a problem using sqlite_last_insert_rowid in PHP. CODE: $database = new SQLiteDatabase(‘example.db’); $sql_1

  • 0

I have a problem using sqlite_last_insert_rowid in PHP.
CODE:

$database = new SQLiteDatabase('example.db');
$sql_1 = "INSERT INTO ex1(test1, test2) VALUES ('$test1','$test2')";
$database->queryExec($sql_1);

$ex1_ID = sqlite_last_insert_rowid($database);

$sql_2 = "INSERT INTO ex2 (ex1_ID, fname, lname) values ('$ex1_ID','$fname','$lname');";
$database->queryExec($sql);

I want to store ID from ex1 table to table ex2 in ex1_ID

CREATE TABLE ex1 ( 
ID INTEGER PRIMARY KEY,
test1 LONGTEXT,
test2 LONGTEXT
);

CREATE TABLE ex2 ( 
ID INTEGER  PRIMARY KEY,
ex1_ID INTEGER,
fname LONGTEXT,
lname LONGTEXT,
FOREIGN KEY ( ex1_ID ) REFERENCES ex1 ( ID )
);

COMPLETE CODE:

$database = new SQLiteDatabase('example.db');
    for ($i = 0; $i < 10; $i++) {
        $test1 = "";
        $test2 = "";
        $lenght = rand(300, 400);
        for ($x = 0; $x < $lenght; $x++) {
            $test1 .= rand(0, 9);
            $test2 .= rand(0, 9);
        }
        $sql_1 = "INSERT INTO ex1 (test1,test2) VALUES ('$test1','$test2')";
        $database->queryExec($sql_1);
        $ex1_ID = sqlite_last_insert_rowid($database);

        for ($j = 0; $j < 3; $j++) {
            for ($x = 0; $x < $lenght; $x++) {
                $test1 .= rand(0, 9);
                $test2 .= rand(0, 9);
            }
            $sql_2 = "INSERT INTO ex2 (ex1_ID, fname, lname) values ('$ex1_ID','$test1','$test2');";
            $database->queryExec($sql_2);
        }
    }

I cant get the last ID from a ex1 table.
Please help!

  • 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-12T09:29:41+00:00Added an answer on June 12, 2026 at 9:29 am

    UPDATED now that we have more information.

    Since you use an object-model way to query your DB, did you try

    $lastid = $database->lastInsertRowid();
    

    ?

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

Sidebar

Related Questions

I was newbie in using sqlite database android. and now I have a problem
i have problem using LIKE structure in DB2 : for example: select * from
I have a problem using a local SQL Server CE database with C# and
I have a problem using the SSIS. I try to import data from database
I have a problem using JSON and arrays. Here is my code: while($row =
i have a problem using the Catch Clipboard Events code found on this link
I have a strange database problem in django, using sqlite: In the Model PrivateMessage:
now, i'm trying to write program using php and sqlite, but i have problem.
I have this database using sqlite, and I'm having problem with closing the cursor
Hi all im using a sqlite helper class, but i have a little problem

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.