可以使用多个/嵌套的MySQLi语句吗? [英] Possible to use multiple/nested MySQLi statements?

查看:72
本文介绍了可以使用多个/嵌套的MySQLi语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在上一条语句的fetch()调用中包含MySQLi prepared statement?如果没有,最好的解决方法是什么?

Is it possible to have a MySQLi prepared statement within the fetch() call of a previous statement? If not, what's the best way around it?

示例代码:

if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) {
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $stmt->bind_result($item);
    while( $stmt->fetch() ) {
        /* Other code here */
        $itemSummary = $item + $magic;
        if($stmt2 = $link->prepare("INSERT INTO summaries (itemID, summary) VALUES (?, ?)")) {
            $stmt2->bind_param("is", $itemID, $itemSummary);
            $stmt2->execute();
            $stmt2->close();
        }
    }
}

推荐答案

您必须能够执行此操作,尽管您必须启动第二个连接.

You should be able to do that, although you make have to start a second connection.

这篇关于可以使用多个/嵌套的MySQLi语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆