autocommit

Autocommit with PDO

£可爱£侵袭症+ 提交于 2020-05-31 04:05:21
问题 The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ? Here is my code: global $bdd; //defined with PDO try { $bdd->beginTransaction(); /* my requests */ $bdd->commit(); } catch (Exception $e) { $bdd->rollBack(); return $e->getMessage(); } return true; } 回答1: $db = new PDO('mysql:dbname=employee'); $db->setAttribute(PDO::ATTR_AUTOCOMMIT,0); var_dump($db->query('SELECT @@autocommit')->fetchAll()); 回答2: I solved

Autocommit with PDO

旧巷老猫 提交于 2020-05-31 04:03:00
问题 The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ? Here is my code: global $bdd; //defined with PDO try { $bdd->beginTransaction(); /* my requests */ $bdd->commit(); } catch (Exception $e) { $bdd->rollBack(); return $e->getMessage(); } return true; } 回答1: $db = new PDO('mysql:dbname=employee'); $db->setAttribute(PDO::ATTR_AUTOCOMMIT,0); var_dump($db->query('SELECT @@autocommit')->fetchAll()); 回答2: I solved

Python 的 MySQLdb 模块插入数据没有成功与 autocommit(自动提交)的关系

雨燕双飞 提交于 2020-02-29 06:16:13
欢迎大家访问我自己架的博客站点 码厩技术博客 ( Now : 码厩 http://www.markjour.com/ ) ! 用 MySQLdb 操作数据库,插入数据之后发现数据库中依然为空,不知原因为何。 开启 mysqld 的 log 设置项之后发现日志文档中更有执行 sql 语句,直接复制语句在客户端中执行也没有问题,那么为什么通过 MySQLdb 的插入全部没有结果呢? 我怀疑是 MySQLdb 的问题,在日志文件中仔细的看了一遍运行的所有sql 语句,在建立连接之后还运行了这句:set autocommit=0。这句话的嫌疑很大,因为这个涉及到一个语句提交执行的问题,而且对于 commit 我有点印象,好像以前学习 MySQLdb 的时候,特意注意到了这点。不管怎样,这就找准了关键字:MySQLdb autocommit 根据网上搜到的结果,可以大概了解到,MySQLdb 在连接后关闭了自动提交,自动提交对于 innodb 引擎很重要,没有这个设置,innodb 引擎就不会真正执行语句。 解决的办法: 1、语句末尾加上“COMMIT;” 2、运行完语句,至少在关闭数据库之前提交一下,如:conn.commit() 3、数据库连接建立之后,设置自动提交,如:conn.autocommit(1) 只是不知道为什么 innodb 会这样,可能是因为这是一个事务型数据库引擎

How to check if autocommit is on or not postgres' psql

给你一囗甜甜゛ 提交于 2020-01-31 04:48:25
问题 I am using postgres 9.5. How can I check if auto commit is on or off? I tried SHOW AUTOCOMMIT where I got ERROR: unrecognized configuration parameter "autocommit" then I did a \set autocommit off and then SHOW AUTOCOMMIT gives me blank output. How can identify if autocommit is on or off? Also can I set it to off while/after the database in created in my sql file? 回答1: According to this Dustin Marx article, you can use: \echo :AUTOCOMMIT If it's desired to "always" have autocommit disabled,

JDBC connection default autoCommit behavior

一世执手 提交于 2020-01-01 07:31:29
问题 I'm working with JDBC to connect to Oracle. I tested connection.setAutoCommit(false) vs connection.setAutoCommit(true) and the results were as expected. While by default connection is supposed to work as if autoCommit(true) [correct me if I'm wrong], but none of the records are being inserted till connection.commit() was called. Any advice regarding default behaviour? String insert = "INSERT INTO MONITOR (number, name,value) VALUES (?,?,?)"; conn = connection; //connection details avoided

Disabling auto-commit in NamedParameterJdbcTemplate.batchUpdate

独自空忆成欢 提交于 2019-12-24 02:06:42
问题 I am doing a batch update into my DB table using NamedParameterJdbcTemplate.batchUpdate , but I would like to disable auto-commit and perform the commit manually. I can set auto-commit mode off from the connection object, but not sure how to do the same using NamedParameterJdbcTemplate object. 回答1: I have done my implementation using TransactionTemplate It has an execute method and I do the business logic inside a callback in this function. transTemplate.execute( new

Postgres setting autocommit off globally

空扰寡人 提交于 2019-12-23 08:47:29
问题 How do you set autocommit off in psql 8.4 at a global level? is there a configuration attribute that i can change that will introduce this behaviour for all dbs on a cluster to start db sessions with autocommit off? 回答1: Simply add the following to ~/.psqlrc : \set AUTOCOMMIT off Note that this only works when using the psql shell! I assume this is what you are talking about? 回答2: Use a transaction if you want want a (open) transaction: BEGIN; INSERT ...; UPDATE ...; COMMIT; -- when you're

python pymysql set autocommit false fails

陌路散爱 提交于 2019-12-22 10:38:44
问题 my script reads MYSQL UPDATE queries from a file and then should execute them at once by using autocommit = 0. However, if I remove conn.commit() it still runs one by one, although I have not commited. Where is the error? import pymysql conn = pymysql.connect(host='x', unix_socket='/tmp/mysql.sock',user='x', passwd='x', db='x') fileHandle = open ( 'mysqlout.txt' ) fileList = fileHandle.readlines() fileHandle.close() i = 1 weiter = input("Execute MYSQL file? ") if (weiter == 'y'): cur = conn

Prevent Oracle Connection autocommit for JNDI Datasource on JBoss 7 (Jeeves DBMS)

痞子三分冷 提交于 2019-12-22 08:06:08
问题 I am currently having an odd situation with the autocommit settings of an Oracle JNDI Datasource in JBoss 7. The outline The application I want to deploy, wich I can inspect but not change, obtains connections from the Connection Pool and trys to commit after certain statements. Obviously the connection has autocommit set to 'true' per default and so an exception is raised. You cannot commit with autocommit set! What I cannot do Due to the fact that I can't change the application source, the

How to make Subversion (or any program) perform periodic commits?

流过昼夜 提交于 2019-12-19 00:43:23
问题 I want to configure my computer so that say every half an hour it automatically commits the program I am working on. I am using a svn repository so even if it was just a script that ran 'svn ci' every 30 min that would be okay. The problem is that I don't know how to do that. Could somebody please tell me, or direct me to something, that would let me get this periodic commit stuff working? Thanks in advance. EDIT: Sorry it appears that I have confused people as to why I would want to do this.