简体   繁体   English

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

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

I am trying to execute stored procedure, i want to have output as an associative array, but i am getting following error.我正在尝试执行存储过程,我想将输出作为关联数组,但出现以下错误。

Call to a member function fetchAll() on boolean在布尔值上调用成员函数 fetchAll()

and following is my PHP script which is calling the procedure以下是我的 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));

If your procedure1 has 4 parameters you should:如果您的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));

If just 2 change first line to $query_text = "CALL procedure1(?,?);";如果只是 2 将第一行更改为$query_text = "CALL procedure1(?,?);"; then.然后。

EDIT If you still ahve your error, try to handle sql error:编辑如果您仍然有错误,请尝试处理 sql 错误:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM