0

我正在尝试使用以下代码调用 mysql 存储过程:

 $mysqli = new mysqli("localhost", "user", "password", "mydatabase");
 $result = $mysqli->query('CALL storedproc_allusers()');

 while($row = $result->fetch_array(MYSQLI_BOTH))
 {
 echo $row['email'] . "<br />";
 }

存储过程是:

 USE `mydatabase`$$
 DROP PROCEDURE IF EXISTS `storedproc_allusers`$$
 CREATE DEFINER=`user`@`xx.xxx.xx.xx` PROCEDURE `storedproc_allusers`()
 BEGIN
 SELECT * FROM users;
 END$$
 DELIMITER ;

我知道我与数据库的连接很好,因为如果我运行一个简单的选择查询,我会得到我所期望的。

当我运行上述内容时,我收到以下错误:

致命错误:在非对象等上调用成员函数 fetch_array() 等等,这导致我认为查询没有返回任何内容。

我使用 SQLYOG 并且可以从那里成功运行该过程。任何帮助,将不胜感激。

4

1 回答 1

0

您可以在这里找到多个示例http://php.net/manual/en/mysqli.quickstart.stored-procedures.php

$mysqli = new mysqli("localhost", "user", "password", "mydatabase");
$mysqli->query('CALL storedproc_allusers()');
do {
    if ($result = $mysqli->store_result()) {
        var_dump($result->fetch_all());
        $result->free();
    }
} while ($mysqli->more_results() && $mysqli->next_result()) ;

尝试这个

于 2014-07-21T18:26:42.943 回答