<legend id='ZNbw8'><style id='ZNbw8'><dir id='ZNbw8'><q id='ZNbw8'></q></dir></style></legend>
    <bdo id='ZNbw8'></bdo><ul id='ZNbw8'></ul>

  1. <small id='ZNbw8'></small><noframes id='ZNbw8'>

      <tfoot id='ZNbw8'></tfoot>
    1. <i id='ZNbw8'><tr id='ZNbw8'><dt id='ZNbw8'><q id='ZNbw8'><span id='ZNbw8'><b id='ZNbw8'><form id='ZNbw8'><ins id='ZNbw8'></ins><ul id='ZNbw8'></ul><sub id='ZNbw8'></sub></form><legend id='ZNbw8'></legend><bdo id='ZNbw8'><pre id='ZNbw8'><center id='ZNbw8'></center></pre></bdo></b><th id='ZNbw8'></th></span></q></dt></tr></i><div id='ZNbw8'><tfoot id='ZNbw8'></tfoot><dl id='ZNbw8'><fieldset id='ZNbw8'></fieldset></dl></div>

      PHP mysqli 为没有参数的存储过程准备的语句

      时间:2023-07-29

        <tbody id='Dj0rW'></tbody>

        <i id='Dj0rW'><tr id='Dj0rW'><dt id='Dj0rW'><q id='Dj0rW'><span id='Dj0rW'><b id='Dj0rW'><form id='Dj0rW'><ins id='Dj0rW'></ins><ul id='Dj0rW'></ul><sub id='Dj0rW'></sub></form><legend id='Dj0rW'></legend><bdo id='Dj0rW'><pre id='Dj0rW'><center id='Dj0rW'></center></pre></bdo></b><th id='Dj0rW'></th></span></q></dt></tr></i><div id='Dj0rW'><tfoot id='Dj0rW'></tfoot><dl id='Dj0rW'><fieldset id='Dj0rW'></fieldset></dl></div>

        <small id='Dj0rW'></small><noframes id='Dj0rW'>

            <bdo id='Dj0rW'></bdo><ul id='Dj0rW'></ul>

            <legend id='Dj0rW'><style id='Dj0rW'><dir id='Dj0rW'><q id='Dj0rW'></q></dir></style></legend>

                <tfoot id='Dj0rW'></tfoot>

              • 本文介绍了PHP mysqli 为没有参数的存储过程准备的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个存储过程 IsUserPresent,例如:

                I have a stored procedure IsUserPresent like:

                DELIMITER $$
                CREATE PROCEDURE IsUserPresent(
                    in userid varchar (150),
                    out isPresent bit
                )
                BEGIN
                    SET isPresent=0;
                    SELECT COUNT(*)
                    INTO isPresent
                    FROM users_table
                    WHERE users_table.userid=userid;
                END$$
                

                我想使用 mysqli 准备好的语句从 PHP 调用它.我正在按照代码片段执行此操作,但它给了我警告.

                and I want to call it from PHP using mysqli prepared statement. I am doing it following code snippet but it gives me warning.

                $connect=&ConnectDB();
                $stmt=$connect->prepare("CALL IsUserPresent(?,?)");
                $stmt->bind_param('si',$uid,$userCount);
                $stmt->execute();
                $toRet = $userCount!=0;
                Disconnect($connect);
                return $toRet;
                

                警告如下:

                Premature end of data (mysqlnd_wireprotocol.c:1112)
                Warning: mysqli_stmt::execute(): RSET_HEADER packet 1 bytes shorter than expected
                Warning: mysqli_stmt::execute(): Error reading result set's header
                

                推荐答案

                存储过程与准备好的语句一起工作的方式有点复杂.PHP 手册 指出您必须使用会话变量(MySQL 会话,而不是 PHP)

                The way stored procedures work with prepared statements is a bit more complicated. PHP manual states that you've got to use session variables (MySQL sessions, not PHP)

                INOUT/OUT 参数

                INOUT/OUT parameter

                使用会话变量访问 INOUT/OUT 参数的值.

                The values of INOUT/OUT parameters are accessed using session variables.

                所以你可以用

                $connect=&ConnectDB();
                // bind the first parameter to the session variable @uid
                $stmt = $connect->prepare('SET @uid := ?');
                $stmt->bind_param('s', $uid);
                $stmt->execute();
                
                // bind the second parameter to the session variable @userCount
                $stmt = $connect->prepare('SET @userCount := ?');
                $stmt->bind_param('i', $userCount);
                $stmt->execute();
                
                // execute the stored Procedure
                $result = $connect->query('call IsUserPresent(@uid, @userCount)');
                
                // getting the value of the OUT parameter
                $r = $connect->query('SELECT @userCount as userCount');
                $row = $r->fetch_assoc();               
                
                $toRet = ($row['userCount'] != 0);
                

                备注:

                我建议将此过程重写为带有一个返回 INT 的 IN 参数的函数.

                I recommend to rewrite this procedure as a function with one IN parameter that returns INT.

                这篇关于PHP mysqli 为没有参数的存储过程准备的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何正确使用 PHP 将 MySQL 对象编码为 JSON? 下一篇:&quot;命令不同步;你现在不能运行这个命令

                相关文章

                最新文章

                  <i id='v9rft'><tr id='v9rft'><dt id='v9rft'><q id='v9rft'><span id='v9rft'><b id='v9rft'><form id='v9rft'><ins id='v9rft'></ins><ul id='v9rft'></ul><sub id='v9rft'></sub></form><legend id='v9rft'></legend><bdo id='v9rft'><pre id='v9rft'><center id='v9rft'></center></pre></bdo></b><th id='v9rft'></th></span></q></dt></tr></i><div id='v9rft'><tfoot id='v9rft'></tfoot><dl id='v9rft'><fieldset id='v9rft'></fieldset></dl></div>

                  <small id='v9rft'></small><noframes id='v9rft'>

                    <bdo id='v9rft'></bdo><ul id='v9rft'></ul>
                1. <legend id='v9rft'><style id='v9rft'><dir id='v9rft'><q id='v9rft'></q></dir></style></legend>

                    <tfoot id='v9rft'></tfoot>