使用node mysql startTransaction 时出现 commit with parameters undefined 错
发布于 11 年前 作者 xlkmuu 5650 次浏览 最后一次编辑是 8 年前

大家好,本人新手 在使用mysql的事务时控制台一直报 commit with parameters undefined 最后 再来个maximun call stack size exceeded 已下是代码,什么都没干就用事务查询了下。

var mysql  = require('mysql');  
var connection = mysql.createConnection({  host : '**',  user : '**',  password : '**'  }); 
 connection.connect(); 
 var queues = require('mysql-queues'); 
const DEBUG = true; 
queues(connection, DEBUG);  
var trans = connection.startTransaction();
trans.query('SELECT * from dbgoods.tb_member', function(err, info) {
 if (err) 
{  
  console.log(123);
throw err;  trans.rollback();  }   
else {  
trans.commit(function(err, info) {  console.log(info);  });
 } 
 });
trans.execute();` console.log('execute');  connection.end();        

求高手解答

2 回复

请把代码markdown排版一下,谢谢。

找到问题了,在事物还没触发返回事件的时候,程序就已经将连接中断了,得把连接中断语句写在事件返回方法里。

connection.end();

这个语句写在:

trans.commit(function(err, info) {
...
//写在这里
connection.end();
}
回到顶部