mysql错误之2014

 

error:2014 Commands out of sync; you can't run this command now

 

这个错误号我也真是醉了。

 

一直纠结于为什么存储过程执行完,commit操作就是不能再mysql的log里被查到呢。

于是试着输出了下错误,然后这个错误就出来了,原因是因为产生了结果集没有释放不能进行后续的提交。

 

 应当释放存储过程产生的数据集,否则一个存储过程执行完不能再进行其他操作。

由于在程序中会多次使用到存储过程,于是我就将其封装在一个方法里面

function runAndClare($conn,$procedure){
	if ($conn->multi_query($procedure))
		do { 
			if ($result = $conn->store_result()) { 
				while ($row = $result->fetch_row()) { 
					;//printf("%s\n", $row[0]); 
				} 
			$result->close(); 
			} 
		} while ($conn->next_result()); 
}

 两个参数分别是new的mysqli实例和存储过程的字符串('call xxxxx()')

 

感觉挺好用的。

posted @ 2014-11-17 09:53  piaomiao1314  阅读(3378)  评论(0编辑  收藏  举报