2 回答
TA贡献1846条经验 获得超7个赞
您可以使用变量变量来动态生成变量名称:
$query = "CALL returnFunction()";
$p_sql = connection::conn()->prepare($query);
$p_sql->execute();
$i = 1;
do {
$rows = $p_sql->fetchAll(PDO::FETCH_NUM);
if ($rows)
{
print_r($rows);
${"v$i"} = $rows;
}
$i++;
} while ($p_sql->nextRowset());
这会将每个非空结果集放入一个变量等中$v1。$v2但是您应该考虑只使用数组:
$query = "CALL returnFunction()";
$p_sql = connection::conn()->prepare($query);
$p_sql->execute();
$v = array();
do {
$rows = $p_sql->fetchAll(PDO::FETCH_NUM);
if ($rows)
{
print_r($rows);
$v[] = $rows;
}
} while ($p_sql->nextRowset());
请注意,如果您也想存储空结果集,请将赋值移到块之外if。
TA贡献1806条经验 获得超5个赞
您可以使用像下面这样的 union 并输出 v1,v2,v3,v4,然后将它们分配给您的变量
SELECT MAX(v1) as v1,MAX(v2) as v2,MAX(v3) as v3,MAX(v4) as v4
FROM
(
SELECT 1.x AS v1,NULL AS v2,NULL AS v3, NULL AS v4
FROM tb_1 AS 1
UNION ALL
SELECT NULL AS v2,2.x AS v2,NULL AS v3, NULL AS v4
FROM tb_2 AS 2
UNION ALL
SELECT NULL AS v2,NULL AS v2,3.x AS v3, NULL AS v4
FROM tb_3 AS 3
UNION ALL
SELECT NULL AS v2,NULL AS v2,NULL AS v3, 4.x AS v4
FROM tb_4 AS 4
) A
- 2 回答
- 0 关注
- 124 浏览
添加回答
举报