I am using mysql extension in php, I know it is deprecated as of PHP 5.5.0, but I have a lot of code allready written with the use of this extension. It seems to me like mysql_query commits the query, if so it means that it is set to autocomit, How to setup so it does not autocommit.
1条回答 默认 最新
- douzhanglu4591 2013-02-08 22:29关注
The old mysql extension doesn't have functions specifically for transaction control, but you can issue SQL statements to do what you want.
You can implicitly turn off autocommit for the duration of one transaction simply by starting a transaction:
mysql_query("START TRANSACTION");
As soon as you COMMIT or ROLLBACK, the autocommit mode will return to the default.
mysql_query("COMMIT"); // or ROLLBACK
You can turn off autocommit for your whole session by setting a session variable:
mysql_query("SET autocommit=0");
Or change it globally on your MySQL instance so it changes the default for all sessions:
mysql_query("SET GLOBAL autocommit=0");
Or set it to change the global setting upon MySQL service startup by editing /etc/my.cnf:
[mysqld] autocommit=0
If you use MySQL 5.1, you have to do this slightly differently:
[mysqld] init_connect='SET autocommit=0'
You probably already know, but it bears repeating that transactions only mean anything if you're using InnoDB tables. MyISAM tables don't support transactions, so they're always autocommit regardless of your settings. Same with several other storage engines, including MEMORY and CSV.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何让企业微信机器人实现消息汇总整合
- ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
- ¥15 如何用Python爬取各高校教师公开的教育和工作经历
- ¥15 TLE9879QXA40 电机驱动
- ¥20 对于工程问题的非线性数学模型进行线性化
- ¥15 Mirare PLUS 进行密钥认证?(详解)
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥20 想用ollama做一个自己的AI数据库
- ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
- ¥15 请问怎么才能复现这样的图呀