mysql出现一个很奇怪的错误

chenyeyu

每次客户端连接后,第一次发送聊天信息,服务器那里执行插入就会出错,再发一次他就正常了。两次发送的信息都是一样的,除了时间。
错误如下:
用的GatewayWorker

INSERT INTO `xf_user_im` (`send_id`,`accept_id`,`sender`,`time`,`type`,`content`,`msg_time`) VALUES ('4','5','guwen','1467941111','txt','7','2016-07-08 09:25:09')exception 'PDOException' with message 'SQLSTATE: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' in /home/socket/GatewayWorker/Lib/DbConnection.php:1720
Stack trace:
#0 /home/socket/GatewayWorker/Lib/DbConnection.php(1720): PDO->prepare('INSERT INTO `xf...')
#1 /home/socket/GatewayWorker/Lib/DbConnection.php(1808): GatewayWorker\Lib\DbConnection->execute('INSERT INTO `xf...', NULL)
#2 /home/socket/Applications/IM/Events.php(126): GatewayWorker\Lib\DbConnection->query('INSERT INTO `xf...')
#3 : Events::onMessage('7f0000010b54000...', '{"accept_id":"5...')
#4 /home/socket/GatewayWorker/BusinessWorker.php(360): call_user_func('Events::onMessa...', '7f0000010b54000...', '{"accept_id":"5...')
#5 : GatewayWorker\BusinessWorker->onGatewayMessage(Object(Workerman\Connection\AsyncTcpConnection), Array)
#6 /home/socket/Workerman/Connection/TcpConnection.php(422): call_user_func(Array, Object(Workerman\Connection\AsyncTcpConnection), Array)
#7 : Workerman\Connection\TcpConnection->baseRead(Resource id #38)
#8 /home/socket/Workerman/Events/Select.php(250): call_user_func_array(Array, Array)
#9 /home/socket/Workerman/Worker.php(1472): Workerman\Events\Select->loop()
#10 /home/socket/GatewayWorker/BusinessWorker.php(174): Workerman\Worker->run()
#11 /home/socket/Workerman/Worker.php(900): GatewayWorker\BusinessWorker->run()
#12 /home/socket/Workerman/Worker.php(866): Workerman\Worker::forkOneWorker(Object(GatewayWorker\BusinessWorker))
#13 /home/socket/Workerman/Worker.php(422): Workerman\Worker::forkWorkers()
#14 /home/socket/start.php(32): Workerman\Worker::runAll()
#15 {main}WORKER EXIT UNEXPECTED 

有谁碰到过吗

3852 4 0
4个回答

chenyeyu

我晕死啊,我发现,是发第一条过来没问题,第二条就有问题,第三没问题,第四条有问题。。。。
我就在onMessage开头这样写而已:

$db1 = Db::instance('zhongjianbao');
if (!$db1) {
return;
}
$db1->row("SELECT id FROM {$pre}user WHERE im_key=''");
return;

  • 暂无评论
chenyeyu

我把系统的PDO换成mysql了,,就没问题了

  • 暂无评论
damao

你的select结果集不是一条记录,是多条记录,但是调用row只取一条,缓冲区中还有未获取的记录,mysql驱动不允许当上一个执行的 PDOStatement 对象仍有未取行时,再执行一个 PDOStatement 对象获取数据。

可以在你的sql里面加个 limit 1应该就能解决问题了。

  • 暂无评论
latin

用完后的PDOStatement调用$PDOStatement->closeCursor()关闭下游标就好了。
但是要改代码数据库的代码。@walkor

年代过于久远,无法发表回答
×
🔝