mysqli准备好的声明,而fetch不起作用

时间:2016-01-24 04:28:07

标签: php mysql mysqli

此方法是更大类的一部分,我试图让它返回包含相同类的对象数组。但是,它似乎没有进入while循环,我无法弄清楚原因。有什么建议吗?

预期结果将是包含此数据http://sqlfiddle.com/#!9/b6e23/1的对象数组。

public static function getAllFacts($groupID)
{
    $factTable = array();

    $conn = new mysqli($GLOBALS['hostName'], $GLOBALS['userName'], $GLOBALS['password'], $GLOBALS['database']);
    if ($conn->connect_error)
    {
        echo "Database connection error (source table)<br>";
    }

    $query = "SELECT factID, sourceID, factTXT, citationID, noteGroupID, factCreated, factsGroupID FROM facts WHERE factsGroupID = ?";

    $stmt = $conn->prepare($query);

    if ($stmt)
    {
        $stmt->bind_param("i", $groupID);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result(
                $factID,
                $sourceID,
                $factTXT,
                $citaitionID,
                $noteGroupID,
                $factCreated,
                $factsGroupID
                );

        $row = 0;  
        while ($stmt->fetch())
        {
            $numRows = $stmt->num_rows;
            echo "numRows: " . $numRows . "<br>";
            $factTable[$row] = new self($factID, $sourceID, $factTxt, $citationTxt, $noteGroupID, $factCreated, $factsGroupID, $numRows);   
            $row++;
        }

        $stmt->close(); 
    }
    else
    {
        echo "Statement failed. (source table) <br>";
    }

    return $factTable;
}

0 个答案:

没有答案