0

我正在尝试将 MySQL 转换为 MySQLi。我不知道为什么它会刹车

$stmt2->execute();

并返回错误:

Call to a member function execute() on a non-object

有任何问题或有效实施它!?

// SQL condition "WHERE group=''" where `group` is empty (NULL)
$result = "SELECT id, name FROM table WHERE group='' ORDER BY array ASC";

if ($stmt = $mysqli->prepare($result)) {
    $stmt->execute();
    $stmt->bind_result($id, $name);

    while ($stmt->fetch()) {
        // SQL condition "WHERE group='$id'" where $id defined in $stmt->bind_result($id, $name);
        $result2 = "SELECT name FROM table WHERE group='$id' ORDER BY array ASC";

        $stmt2 = $mysqli->prepare($result2);
        //$valid_stmt2 = $stmt2 === FALSE ? false : true;

        echo $name . "\n";

        //if ($valid_stmt2) {
            // Error cased on $stmt2->execute();
            $stmt2->execute();
            $stmt2->bind_result($name2);

            while ($stmt2->fetch()) {
                echo 'related to: ' . $name2 . "\n";
            }

            $stmt2->close();
        //}
    }

    $stmt->free_result();
    $stmt->close();
}

这个问题可能与可能使用多个/嵌套的 MySQLi 语句有关?不幸的是,我没有发现它有帮助,因为它没有提供有效的示例或问题资源。

更新:带有注释的简化代码示例。

4

1 回答 1

0

你先做了

"SELECT id, url, name FROM links WHERE group='' ORDER BY array ASC"

然后你想用$idto do

"SELECT url, name FROM links WHERE group='$id' ORDER BY array ASC"

如何获得结果?如果 group 等于空字符串,那么它将不等于$id(仅当$id也是空字符串但这是没有意义的。)

于 2012-06-15T01:49:58.653 回答