Are you familiar with transactions or PDO? Always roll back and delete data solution-php Tutorial

Source: Internet
Author: User
Are you familiar with transactions or PDO? Always roll back and the data database type cannot be deleted: sqlite & nbsp; no error is Prompted. one row is tested and there is no error. why always roll back? I always roll back. I cannot delete the data. & nbsp; what are the reasons? The following is the descriptive code: PHPcode $ king-& gt; db-& gt; connect (); connect to the database $ link as the database connection handle. $ King-& Are you familiar with transactions or PDO? Always roll back, data cannot be deleted
Database type: sqlite
No error is Prompted. there is indeed no error in one row of tests. why is it always rolled back? Always roll back, data cannot be deleted
What are the possible reasons?
The following is the descriptive code:

PHP code
  $ King-> db-> connect (); // connect to the database $ link is the database connection handle. $ King-> db-> link-> beginTransaction (); // if ($ rs1 = $ king-> db-> getRows_number ('% s_newsContent ', "newsID in ($ newsID)") {if ($ rs2 = $ king-> db-> query ("delete from % s_newsContent where newsID in ($ newsID )")) {$ s. = "news content deleted! [". $ Rs2."/". $ rs1."]
";} Else {lzj_message ('failed to delete news content', 'javascript: history. go (-1) ') ;}} if ($ rs1 = $ king-> db-> getRows_number (' % s_rss ', "idValue in ($ newsID) and tableName = 'new' and idName = 'newsid '")) {if ($ rs2 = $ king-> db-> query ("delete from % s_rss where tableName = 'news' and idName = 'newsid 'and idValue in ($ newsID) ") {$ s. = "News RSS has been deleted! [". $ Rs2."/". $ rs1."]
";} Else {lzj_message ('failed to delete the News RSS ', 'javascript: history. go (-1) ') ;}}if ($ rs = $ king-> db-> query ("delete from % s_news where newsID in (". $ newsID. ")") {lzj_message ("deleted successfully! [". $ Rs."]
". $ S, $ pageUrl);} else {lzj_message ('news deletion failed', 'javascript: history. go (-1) ');} $ king-> db-> link-> commit (); // roll back the end point


------ Solution --------------------
I feel you have a problem writing this method.
You can set up an identifier such as flag = true at the beginning of a transaction;

If ($ flag ){
Your operations ........
} Else {
..............
$ Flag = false;
}
Continue the next operation as above


Last
If ($ flag ){
Submit things
} Else {

Rollback
}

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.