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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:57:49+00:00 2026-05-30T09:57:49+00:00

Since the subscriber table auto- inc number will append 1 even though the transaction

  • 0

Since the subscriber table auto- inc number will append 1 even though the transaction error occur and the roll back does not help. Then it can not add the information in list_ sub table since the id is not consistent ,so I use

alter tableid auto inc =1

to minus the auto inc number and i put it in the catch block without another try- catch. But is it common practice? Thankyou

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
$conn->beginTransaction();
try {

    $email = $_POST['Email'];
    $FirstName = $_POST['FirstName'];
    $LastName = $_POST['LastName'];


    $query="INSERT INTO subscriber (Email,FirstName,LastName,CreateDate) VALUES (?,?,?,CURDATE())";
    $stmt = $conn->prepare($query);


    $stmt->bindParam(1, $email , PDO::PARAM_STR);
    $stmt->bindParam(2, $FirstName, PDO::PARAM_STR);
    $stmt->bindParam(3, $LastName, PDO::PARAM_STR);
    $stmt->execute();
    $conn->commit();

}
catch(PDOException $e)
    {
    $conn->rollBack();
    $query="ALTER TABLE subscriber AUTO_INCREMENT = 1";
    $stmt = $conn->prepare($query);
    $stmt->execute();
    die ($e->getMessage()."<a href='addSub.php'>Back</a>");
    }

$conn->beginTransaction();
try {
    $userID = $_SESSION['username'];
    $query="INSERT INTO list_sub (SubID,ListID) VALUES ('',$_SESSION[ListID])";
    $stmt = $conn->prepare($query);
    $stmt->execute();
    $conn->commit();

}
catch(PDOException $e)
    {
    $conn->rollBack();
    die ($e->getMessage()."<a href='addSub.php'>Back</a>");
    }

$conn = null;}

Table:Subsciber

 1  SubID   int(11)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  Email   varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
 3  FirstName   varchar(100)    utf8_general_ci     Yes NULL          Change      Drop   More 
 4  LastName    varchar(100)    utf8_general_ci     Yes NULL          Change      Drop   More 
 5  CreateDate  date            No  None          Change      Drop   More 
 6  UpdateDate  date            Yes NULL          Change      Drop   More   Check All / Uncheck All With selected:   Browse  Change  Drop  Primary  Unique  Index

Table:list_sub

 1  SubID   int(11)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  ListID  int(11)         No  None          Change      Drop   More 

Table:list

 1  ListID  int(11)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  ListName    varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
 3  FromName    varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
 4  ReplyTo varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
 5  Subject varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
 6  IsRemindSub tinyint(1)          No  None          Change      Drop   More 
 7  IsRemindUnSub   tinyint(1)          No  None          Change      Drop   More 
 8  CreateDate  date            No  None          Change      Drop   More 
 9  Reminder    varchar(100)    utf8_general_ci     No  None          Change      Drop   More 
  • 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-30T09:57:50+00:00Added an answer on May 30, 2026 at 9:57 am

    I think it is bad design to have a meaningful auto-increment field, for reasons such as the one that you describe. It is not always possible to ensure that numbers will be allocated the way you want them to be.

    In this case the imperative seems to be that subscriber number 16 (say) is the 16th subscriber. But do the subscriber numbers absolutely have to be contiguous in this way? My concern is that you are adding extra complexity to your code, in order to satisfy this rule. I value simplicity above all else.

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

Sidebar

Related Questions

Since both a Table Scan and a Clustered Index Scan essentially scan all records
It's been a while since I did Java work, and even then I was
I happen to be a subscriber of Ruby Inside, since I'm particularly interested in
I have two MySQL tables like this: User Id (PK, auto-increment integer) Subscriber Id
Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better,
Since CS3 doesn't have a web service component, as previous versions had, is there
Since Graduating from a very small school in 2006 with a badly shaped &
Since the WMI class Win32_OperatingSystem only includes OSArchitecture in Windows Vista, I quickly wrote
Since debate without meaningful terms is meaningless , I figured I would point at
Since the keyboard is the interface we use to the computer, I've always thought

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.