gpt4 book ai didi

mysql - 在没有同步错误的情况下在另一个循环中运行 mysql 查询

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:38 24 4
gpt4 key购买 nike

如果我有这样的代码(忽略初始化连接和句柄等不相关的事情):

MYSQL_RES *res;
MYSQL_ROW row;
mysql_query(mysql, "some select query");
res = mysql_use_result(mysql);
while (row = mysql_fetch_row(res)) {
MYSQL_RES *res2;
MYSQL_ROW row2;
mysql_query(mysql, "some other select query using an id from the first");
res2 = mysql_use_result(mysql);
/* ... */
mysql_free_result(res2);
}
mysql_free_result(res);

每当我运行第二个 mysql_query(在循环中)时,我都会收到错误

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

如何在从一个选择查询中获取行的同时运行另一个选择查询?

最佳答案

我向 MySQL 邮件列表发送了一封电子邮件。基本上,为了能够做到这一点,我需要有两个独立的 MySQL 连接。谢谢,Shawn Green(来自 Oracle)。

The mysql object you are using for your connection can only have one active query or result on it at a time. To have two sets of results working, you need a second independent connection to the MySQL server

关于mysql - 在没有同步错误的情况下在另一个循环中运行 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4734078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com