使用php / mysqli中的存储过程检索多个结果集
我有一个存储过程有多个结果集.如何提前到
mysqli的第二个结果集获得这些结果?
让我们说这是一个存储过程: create procedure multiples( param1 INT,param2 INT ) BEGIN SELECT * FROM table1 WHERE id = param1; SELECT * FROM table2 WHERE id = param2; END $$ PHP是这样的: $stmt = mysqli_prepare($db,'CALL multiples(?,?)'); mysqli_stmt_bind_param( $stmt,'ii',$param1,$param2 ); mysqli_stmt_execute( $stmt ); mysqli_stmt_bind_result( $stmt,$id ); 那么这是我无法上班的部分.我已经尝试使用mysqli_next_result移动到下一个结果集,但不能让它工作.我们确实可以使用mysqli_store_result和mysqli_fetch_assoc / array / row,但是由于某些原因,所有的int都被返回为空字符串. 任何其他人都会遇到这个问题,并有解决办法吗?
我想你在这里遗漏了一些东西(以下未经测试):
$stmt = mysqli_prepare($db,?)'); mysqli_stmt_bind_param($stmt,$param2); mysqli_stmt_execute($stmt); // fetch the first result set $result1 = mysqli_use_result($db); // you have to read the result set here while ($row = $result1->fetch_assoc()) { printf("%dn",$row['id']); } // now we're at the end of our first result set. mysqli_free_result($result1); //move to next result set mysqli_next_result($db); $result2 = mysqli_use_result($db); // you have to read the result set here while ($row = $result2->fetch_assoc()) { printf("%dn",$row['id']); } // now we're at the end of our second result set. mysqli_free_result($result2); // close statement mysqli_stmt_close($stmt); 使用 $stmt = $db->prepare('CALL multiples(:param1,:param2)'); $stmt->execute(array(':param1' => $param1,':param2' => $param2)); // read first result set while ($row = $stmt->fetch()) { printf("%dn",$row['id']); } $stmt->nextRowset(); // read second result set while ($row = $stmt->fetch()) { printf("%dn",$row['id']); } 但是听说 > PDO nextRowset not working on MySQL 所以,根据您的PHP版本,您必须坚持使用您的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |