缺少存储过程的第一个结果
First result of Stored Procedure is missing
我执行存储过程的查询,其中有 3 个结果 select
select _id a;
select 2 a;
select 3 a;
我有这样的 mysqli 来调用存储过程
$i = 0;
if ($server->connection->query("CALL sp_select(1)", MYSQLI_USE_RESULT)) {
printf("res\n");
do {
$i++;
printf("$i.do\n");
if ($result = $server->connection->store_result()) {
printf("$i.store\n");
$data = $result->fetch_all(MYSQLI_ASSOC);
$this->data[] = $data;
$result->free_result();
printf("$i.free\n");
}
if ($server->connection->more_results()) {
printf("$i.more\n");
}
} while ($server->connection->next_result());
echo json_encode($this->data);
}
该函数无法存储第一个结果。我只得到了第二和第三的结果。
为什么我无法存储第一个结果?
当使用 mysqli_query()
调用存储过程时,第一个结果是 return 从函数本身编辑的。像这样的东西也应该收集第一个结果。
$result = $mysqli->query("CALL sp_select()");
$this->data[] = $result->fetch_all();
while ($mysqli->next_result()) {
if ($result = $mysqli->store_result()) {
$this->data[] = $result->fetch_all();
}
}
echo json_encode($this->data);
您似乎混淆了 query()
和 multi_query()
,这不是 return 初始结果。此代码将执行相同的操作:
$mysqli->multi_query("CALL sp_select()");
do {
if ($result = $mysqli->store_result()) {
$this->data[] = $result->fetch_all();
}
} while ($mysqli->next_result());
echo json_encode($this->data);
我执行存储过程的查询,其中有 3 个结果 select
select _id a;
select 2 a;
select 3 a;
我有这样的 mysqli 来调用存储过程
$i = 0;
if ($server->connection->query("CALL sp_select(1)", MYSQLI_USE_RESULT)) {
printf("res\n");
do {
$i++;
printf("$i.do\n");
if ($result = $server->connection->store_result()) {
printf("$i.store\n");
$data = $result->fetch_all(MYSQLI_ASSOC);
$this->data[] = $data;
$result->free_result();
printf("$i.free\n");
}
if ($server->connection->more_results()) {
printf("$i.more\n");
}
} while ($server->connection->next_result());
echo json_encode($this->data);
}
该函数无法存储第一个结果。我只得到了第二和第三的结果。 为什么我无法存储第一个结果?
当使用 mysqli_query()
调用存储过程时,第一个结果是 return 从函数本身编辑的。像这样的东西也应该收集第一个结果。
$result = $mysqli->query("CALL sp_select()");
$this->data[] = $result->fetch_all();
while ($mysqli->next_result()) {
if ($result = $mysqli->store_result()) {
$this->data[] = $result->fetch_all();
}
}
echo json_encode($this->data);
您似乎混淆了 query()
和 multi_query()
,这不是 return 初始结果。此代码将执行相同的操作:
$mysqli->multi_query("CALL sp_select()");
do {
if ($result = $mysqli->store_result()) {
$this->data[] = $result->fetch_all();
}
} while ($mysqli->next_result());
echo json_encode($this->data);