How to delete a piece of data and insert it into another table-php Tutorial

Source: Internet
Author: User
How to delete a piece of data and insert this data into another one is shown in two tables: sns_topic and sns_topic_del. edit the data on the list page of the sns_topic table, if you want to delete a piece of data and insert it into the sns_topic_del table, how can this problem be solved? ------ Solution ------------------ execute two queries, INSERT and DELETE first. to ensure data consistency, you have to DELETE a piece of data and INSERT the data into another table.
Now there are two sns_topic and sns_topic_del tables. you can edit the sns_topic on the list page of the sns_topic table. you need to delete a piece of data and insert it into the sns_topic_del table. how can this problem be solved?

------ Solution --------------------
Execute two queries: INSERT and DELETE. to ensure data consistency, you must use the statement as a transaction.
------ Solution --------------------
Create a trigger in the database!
------ Solution --------------------
PHP code
Mysql_query ("start transaction"); $ sql1 = mysql_query ('Insert statement'); $ sql2 = mysql_query ('delete statement'); if ($ sql1 & $ sql2) {// submit mysql_query ('commit ');} else {// transaction ROLLBACK mysql_query ('rollback');} mysql_query ('end ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.