如何在多查询 mysql 和 php 中识别特定的 select 语句

How to identify a particular select statement in multiquery mysqli and php

我在 PHP 中创建了一个包含多个 select 查询的存储过程。我正在使用 mysqli_multi_query 来调用过程,我正在使用 mysqli_store_result 来存储 select 查询的结果。

问题是我想识别 select 查询,哪个 select 查询正在获取结果,我想唯一地标记它

您可以为每个查询添加一个额外的列,如下所示:

select 'query_tag_1' as tag, ...
from your_table;

select 'query_tag_2' as tag, ...
from your_table;

select 'query_tag_3' as tag, ...
from your_table;

您可以检查 PHP 中 tag 列的值。

更新:另一种方法是重命名列(例如第一个):

select id as id_tag1, ...
from your_table;

select id as id_tag2, ...
from your_table;

select id as id_tag3, ...
from your_table;