简体   繁体   中英

PHP transaction are not working on my wamp

I want to upload some data in my table which is innoDB but every time I want to clean the data stored in the table, so i run a truncate command to do this. But if my insert query goes false then I want that table to get rollback. Below code does not work for me. Am I missing something? Someone help me on this please?

function begin() {
    mysql_query("BEGIN");
}

function commit() {
    mysql_query("COMMIT");
}

function rollback() {
    mysql_query("ROLLBACK");
}

begin();
mysql_query("TRUNCATE TABLE table_name");

if(mysql_query("Any bad insert query"))
{
    commit();
}
else
{
    rollback();
}

TRUNCATE TABLE causes implicit commit (ie it can't be rolled back). Use DELETE instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM