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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:36:19+00:00 2026-06-12T15:36:19+00:00

I’m developing a php/MySQLi based site. I have a question about what might happen

  • 0

I’m developing a php/MySQLi based site. I have a question about what might happen if the page for some reason crashes in the middle of executing a complex procedure.

Example:

if (get_message_call)
{
    add something to table 1
    add something to table 2
    add something to table 3   ( based on some values inserted into table2 ) 
    add something to table 4
    etc...
}

I’ve built the database using PHPmyAdmin (InnoDB). I haven’t assigned any relations though since primary/foreign keys didn’t work out as in theory (perhaps i dit it wrong).

My main concern is that if the statement for some reason gets aborted (page crash, loose connection etc) in the middle of lets say executing the “add something to table3”. I guess that the first and second statement will get executed, and the rest wont?

What is the best way to ensure that this wont be possible to occur since it might mess up the keys etc for the other tables.. i might be a bit fuzzy with the explenation but i hope someone understands my point.

I’ve read about “Rollbacks and Commits in Stored Procedures and Triggers” but i’m not sure if i understood it right..

Thanks in advance.

  • 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-12T15:36:20+00:00Added an answer on June 12, 2026 at 3:36 pm

    This is a case where you should use a database transaction. When you have to update multiple tables, and the updates depend on previous updates, it is safest to put the code into a stored procedure on the database. The stored procedure can start a transaction, which will commit the data to the database only if it finishes correctly (it means that if you write to one table, write to a second table, but the third write fails, the first and second writes are also rolled back).

    Here is an example – the stored procedure takes 3 input arguments, returns 2 output values and updates 3 tables. If there is any error, the transaction rolls back. (Note this is just an example, there may be minor syntax errors)

    CREATE DEFINER=`root`@`localhost` PROCEDURE `doSomething`(
      IN input1 INT,
      IN input2 VARCHAR(255),
      IN input3 VARCHAR(100),
      OUT output1 INT,
      OUT output2 INT
    )
    BEGIN
    DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; END;
    DECLARE EXIT HANDLER FOR SQLWARNING BEGIN ROLLBACK; END;
    DECLARE EXIT HANDLER FOR NOT FOUND BEGIN ROLLBACK; END;
    
    START TRANSACTION;
    
    INSERT INTO table1 (column1, column2, column3) VALUES (input1, input2, NOW());
    SET @new_row_id = LAST_INSERT_ID();
    
    
    INSERT INTO table2 (column1, colum2) VALUES (@new_row_id, input3);
    SET @other_new_row_id = LAST_INSERT_ID();
    
    UPDATE table3 SET mycolumn = @other_new_row_id WHERE id = @new_row_id;
    
    COMMIT;
    
    SET output1 = @new_row_id;
    SET output2 = @other_new_row_id;
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.