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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:31:35+00:00 2026-05-12T15:31:35+00:00

I have 2 tables: user_tb.username user_tb.point review_tb.username review_tb.review I am coding with PHP(CodeIgniter). So

  • 0

I have 2 tables:

user_tb.username
user_tb.point

review_tb.username
review_tb.review

I am coding with PHP(CodeIgniter). So I am trying to insert data into review_tb with the review the user had submitted and if that is a success, i will award the user with some points.

Well this look like a very simple process. We will first insert the review into the review_tb with the username and use PHP to check if there is any problem with the query executed and if it’s a success, we will proceed with updating the points in the user_tb.

Yea, but here comes the problem. What if inserting into review_tb is a success but the second query, inserting into the user_tb is NOT a success, can we kind of “undo” the review_tb query or “revert” the change that we did to review_tb.

It’s kind of like “all or nothing”.

The purpose of this is to sync all data across the database, where in real life, we will be managing a database of more tables, and inserting more data into each table which depends on each other.

Please give some enlightenment on how we can do this in PHP or CodeIgniter or just MySql query.

  • 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-12T15:31:35+00:00Added an answer on May 12, 2026 at 3:31 pm

    If you want a “all or nothing” behavior for your SQL operations, you are looking for transactions ; here is the relevant page from the MySQL manual : 12.4.1. START TRANSACTION, COMMIT, and ROLLBACK Syntax.

    Wikipedia describes those this way :

    A database transaction comprises a
    unit of work performed within a
    database management system (or
    similar system)
    against a database,
    and treated in a coherent and reliable
    way independent of other transactions.
    Transactions in a database environment
    have two main purposes:

    1. To provide reliable units of work that allow correct recovery from
      failures and keep a database
      consistent even in cases of system
      failure, when execution stops
      (completely or partially) and many
      operations upon a database remain
      uncompleted, with unclear status.
    2. To provide isolation between programs accessing a database
      concurrently. Without isolation the
      programs’ outcomes are typically
      erroneous.

    Basically :

    • you start a transaction
    • you do what you have to ; ie, your first insert, and your update
    • if everything is OK, you commit the transaction
    • else, if there is any problem with any of your queries, you rollback the transaction ; and it will cancel everything you did in that transaction.

    There is a manual page about transactions and CodeIgniter here.

    Note that, with MySQL, no every Engine supports transaction ; between the two most used engines, MyISAM doesn’t support transactions, while InnoDB supports them.

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

Sidebar

Related Questions

I have 2 tables - one storing user information (id, username, password) and the
I have two tables User ID UserName 1 Name1 2 Name2 3 Name3 4
I have three tables: USER: user_id (pk); username FIELD: field_id (pk); name METADATA: metadata_id
I have two tables USER and TRANSACTION i want to choose the data from
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have 3 tables - user, service and ratings. The user's primary key is
I have two tables user and log. I would like to join the user
Take tables: User, Comment, Snippet. A User can have many Snippets. A Snippet can
I created 3 tables: User User-Group Group Where I can have a many-to-many relationship.
I have three tables which are defined as: class User(Base): __tablename__ = 'users' id

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.