在 MYSQL 存储过程上调用成员函数 fetchAll()

Call to a member function fetchAll() on MYSQL Stored Procedure

我正在尝试执行存储过程,我想将输出作为关联数组,但出现以下错误。

Call to a member function fetchAll() on boolean

下面是我的 PHP 调用程序的脚本

        $query_text = "CALL procedure1(?,?,@mobNum,@firstInsert);";
        $output=$this->pdo->prepare($query_text);
        $output=$output->execute(array($number,$code));
print_r($output->fetchAll(PDO::FETCH_ASSOC));

如果您的 procedure1 有 4 个参数,您应该:

$query_text = "CALL procedure1(?,?, @mobNum, @firstInsert);";
$stmt = $this->pdo->prepare($query_text);
$stmt->bindParam(1,$number);
$stmt->bindParam(2,$code);
$result = $stmt->execute();
print_r($stmt->fetchAll(PDO::FETCH_ASSOC));

如果只是 2 将第一行更改为 $query_text = "CALL procedure1(?,?);"; 那么。

编辑 如果您仍然遇到错误,请尝试处理 sql 错误:

if ($result) {
    print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
} else {
    echo "\nPDOStatement::errorInfo():\n";
    $arr = $stmt->errorInfo();
    print_r($arr);
}