doucai5315 2013-02-08 22:20
浏览 50
已采纳

mysql_query是否提交了所有内容

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿