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.

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

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致