skip to Main Content

I am currently working on a project which will have so many queries run a same time. and I am sending data to database in one table and want to check if the data is successfully inserted. I read about mysql_affected_rows(); function and that it will return the values but for example I will have approx 100 tables and as by user going to use my application it will sending data to different table at same times. so the question is how do mysql_affected_rows() will work. because at a same time its gonna be multiple queries in different table. as mysql_affected_rows will need only database connection and it will return the last updation in the database.
how do I can check the data update on the table which I want to check.
example I have a table name user_info. I want to see if data is inserted successfully in the table or not. as mysql_affected_rows() will return the last database updation as it doesn’t matter on which table. it will return the database updatation. but in mean while if some else query hit the database and mysql_affected_rows will return the query as succesfull.
I hope my question is clear.

2

Answers


  1. Chosen as BEST ANSWER

    Its done with the Error handling if its not returning any error yes its added to database


  2. If you are using AUTO_INCREMENT with your column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL. Insert some records in the table using insert command. Display all records from the table using select statement.

    CREATE TABLE t (
      id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
      f VARCHAR(1)) 
    ENGINE = InnoDB;
    
    INSERT INTO t(f) VALUES('a');
    
    SELECT LAST_INSERT_ID();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search