栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用php / mysqli中的存储过程检索多个结果集

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用php / mysqli中的存储过程检索多个结果集

我认为您在这里缺少什么(以下内容尚未经过测试):

$stmt = mysqli_prepare($db, 'CALL multiples(?, ?)');mysqli_stmt_bind_param($stmt, 'ii', $param1, $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 setmysqli_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 statementmysqli_stmt_close($stmt);

使用

PDO
您的代码如下所示:

$stmt = $db->prepare('CALL multiples(:param1, :param2)');$stmt->execute(array(':param1' => $param1, ':param2' => $param2));// read first result setwhile ($row = $stmt->fetch()) {    printf("%dn", $row['id']);}$stmt->nextRowset();// read second result setwhile ($row = $stmt->fetch()) {    printf("%dn", $row['id']);}

但我听说MySQL PDO驱动程序

PDOStatement::nextRowset()
未实现,因此无法检索多个结果集:

  • PDO nextRowset在MySQL上不起作用
  • pdo_mysql:存储过程调用返回单个行集会阻止将来的查询
  • 无法在Windows上使用来自PDO的存储过程

因此,根据您的PHP版本,您必须坚持使用

mysqli
-solution。顺便说一句:您是否故意使用程序样式?使用面向对象的样式
mysqli
将使您的代码看起来更具吸引力(我个人认为)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417039.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号