简体   繁体   English

存储过程准备语句错误mysql php

[英]stored procedure prepared statement bug mysql php

Here's my stored procedure: 这是我的存储过程:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `testProc`(IN num INT, INOUT num2 INT(11))
BEGIN
    set num2 = num+num2+7;
END

Here's the code that calls it: 这是调用它的代码:

if ($stmt = mysqli_prepare($con, 'call testProc(?,?)')) {
    mysqli_stmt_bind_param($stmt, 'ii', $type, $newId);
    mysqli_stmt_execute($stmt);
    echo $newId;
    exit;
    }

This is the error I get: 这是我得到的错误:

<b>Warning</b>:  mysqli_stmt_execute(): Premature end of data (mysqlnd_wireprotocol.c:1116) in

I don't understand. 我不明白 How can something so simple fail? 如此简单的事情怎么会失败? I was just trying to work out how to get a value back from a prepared statement with a stored procedure when I ran up against this brick wall while trying to set up a simple example. 当我试图建立一个简单的示例时,我碰到这堵砖墙时,我只是想尝试如何通过存储过程从准备好的语句中获取值。 Please help, because until I can solve this I can't provide an example so I can't get my real problem solved. 请帮忙,因为在我无法解决此问题之前,我无法提供示例,因此我无法解决实际问题。 Thanks. 谢谢。

I think you should be using bind_result after bind_param. 我认为您应该在bind_param之后使用bind_result。

Check out http://php.net/manual/en/mysqli-stmt.bind-result.php 查看http://php.net/manual/en/mysqli-stmt.bind-result.php

and a previous stack overflow question: mysqli bind_param() fatal error 和先前的堆栈溢出问题: mysqli bind_param()致命错误

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

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