• <bdo id='fgNVd'></bdo><ul id='fgNVd'></ul>

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

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

    2. 获取关联数组时如何消除致命错误

      时间:2023-07-29

      • <tfoot id='G3rZE'></tfoot>

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

            • <bdo id='G3rZE'></bdo><ul id='G3rZE'></ul>

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

            • <i id='G3rZE'><tr id='G3rZE'><dt id='G3rZE'><q id='G3rZE'><span id='G3rZE'><b id='G3rZE'><form id='G3rZE'><ins id='G3rZE'></ins><ul id='G3rZE'></ul><sub id='G3rZE'></sub></form><legend id='G3rZE'></legend><bdo id='G3rZE'><pre id='G3rZE'><center id='G3rZE'></center></pre></bdo></b><th id='G3rZE'></th></span></q></dt></tr></i><div id='G3rZE'><tfoot id='G3rZE'></tfoot><dl id='G3rZE'><fieldset id='G3rZE'></fieldset></dl></div>
                  <tbody id='G3rZE'></tbody>
              1. 本文介绍了获取关联数组时如何消除致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在我的 php/mysqli 代码中收到一个致命错误,它在第 46 行指出:

                I am receiving a fatal error in my php/mysqli code which states that on line 46:

                Fatal error: Call to undefined method mysqli_stmt::fetch_assoc() in ...
                

                我只想知道如何消除这个致命错误?

                I just want to know how can I remove this fatal error?

                它指向的代码行在这里:

                The line of code it is pointing at is here:

                $row = $stmt->fetch_assoc();
                

                原始代码:

                $query = "SELECT Username, Email FROM User WHERE User = ?";
                // prepare query
                $stmt=$mysqli->prepare($query);
                // You only need to call bind_param once
                $stmt->bind_param("s",$user);
                // execute query
                $stmt->execute(); 
                // get result and assign variables (prefix with db)
                $stmt->bind_result($dbUser, $dbEmail);
                //get number of rows
                $stmt->store_result();
                $numrows = $stmt->num_rows();                                      
                
                if ($numrows == 1){
                
                $row = $stmt->fetch_assoc();
                $dbemail = $row['Email'];
                
                }
                

                更新代码:

                $query = "SELECT Username, Email FROM User WHERE User = ?";
                // prepare query
                $stmt=$mysqli->prepare($query);
                // You only need to call bind_param once
                $stmt->bind_param("s",$user);
                // execute query
                $stmt->execute(); 
                // get result and assign variables (prefix with db)
                $stmt->bind_result($dbUser, $dbEmail);
                //get number of rows
                $stmt->store_result();
                $numrows = $stmt->num_rows();                                      
                
                if ($numrows == 1){    
                  $row = $stmt->fetch_assoc();
                  $dbemail = $row['Email'];    
                }
                

                推荐答案

                变量 $stmt 的类型是 mysqli_stmt,而不是 mysqli_result.mysqli_stmt 类没有为其定义方法fetch_assoc()".

                The variable $stmt is of type mysqli_stmt, not mysqli_result. The mysqli_stmt class doesn't have a method "fetch_assoc()" defined for it.

                您可以通过调用其 get_result() 方法从 mysqli_stmt 对象中获取 mysqli_result 对象.为此,您需要安装 mysqlInd 驱动程序

                You can get a mysqli_result object from your mysqli_stmt object by calling its get_result() method. For this you need the mysqlInd driver installed!

                $result = $stmt->get_result();
                row = $result->fetch_assoc();
                

                如果您没有安装驱动程序,您可以像这样获取结果:

                If you don't have the driver installed you can fetch your results like this:

                $stmt->bind_result($dbUser, $dbEmail);
                while ($stmt->fetch()) {
                    printf("%s %s
                ", $dbUser, $dbEmail);
                }
                

                所以你的代码应该变成:

                So your code should become:

                $query = "SELECT Username, Email FROM User WHERE User = ?";
                // prepare query
                $stmt=$mysqli->prepare($query);
                // You only need to call bind_param once
                $stmt->bind_param("s",$user);
                // execute query
                $stmt->execute(); 
                // bind variables to result
                $stmt->bind_result($dbUser, $dbEmail);
                //fetch the first result row, this pumps the result values in the bound variables
                if($stmt->fetch()){
                    echo 'result is ' . dbEmail;
                }
                

                这篇关于获取关联数组时如何消除致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli bind_param() 致命错误 下一篇:在这个 php 配置中是否启用了 mysqli 扩展?

                相关文章

                最新文章

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

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