• <tfoot id='8xtFY'></tfoot>

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

    1. <small id='8xtFY'></small><noframes id='8xtFY'>

      1. 使用 PHP SESSION 变量存储 MySQL 查询结果

        时间:2023-07-29

      2. <small id='8P7M5'></small><noframes id='8P7M5'>

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

                <tfoot id='8P7M5'></tfoot>
                  <tbody id='8P7M5'></tbody>
                <i id='8P7M5'><tr id='8P7M5'><dt id='8P7M5'><q id='8P7M5'><span id='8P7M5'><b id='8P7M5'><form id='8P7M5'><ins id='8P7M5'></ins><ul id='8P7M5'></ul><sub id='8P7M5'></sub></form><legend id='8P7M5'></legend><bdo id='8P7M5'><pre id='8P7M5'><center id='8P7M5'></center></pre></bdo></b><th id='8P7M5'></th></span></q></dt></tr></i><div id='8P7M5'><tfoot id='8P7M5'></tfoot><dl id='8P7M5'><fieldset id='8P7M5'></fieldset></dl></div>
                1. 本文介绍了使用 PHP SESSION 变量存储 MySQL 查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在一个文件中执行查询,将其存储在会话变量中,然后在另一个文件中访问结果.

                  I want to execute a query in one file, store it in a session variable, and access the result in another file.

                  File1.php:

                  //This is the file I have executed my sql statement in
                  //I have already done session_start(); and initialized $conn
                  $query = //my query. I know it is working because I have tested it elsewhere, so I 
                           // don't believe it is the problem
                  $_SESSION['query2'] = mysqli_query($conn, $query)
                  

                  File2.php:

                  //This is the file I want to access my query results in.
                  //I have already done session_start(); and initialized $conn
                  
                  $tempArray =  $_SESSION['query2'];
                  
                  if (isset($tempArray)) {
                      $row = mysqli_fetch_array($tempArray, MYSQL_NUM);
                      if ($row == null) {
                          echo "<h1> error </h1>"; //This line gets executed
                      } else {
                          echo "<h1> works! </h1>";
                      }
                  } else {
                      echo "<h1> array not set </h1>";
                  }
                  

                  对我做错了什么有任何想法吗?或者,有没有其他方法可以完成我在这里尝试做的事情?

                  Any ideas as to what I am doing wrong? Or, is there another way to accomplish what I'm trying to do here?

                  推荐答案

                  在会话中存储实际数组:

                  Store the actual array in session:

                  File1.php:
                  
                  $query = //my query. 
                  $result = array();
                  $res = mysqli_query($conn, $query);
                  while($row = mysqli_fetch_array($res, MYSQL_NUM){
                      $result[] = $row;
                  }
                  $_SESSION['query2'] = $result;
                  
                  File2.php:
                  //I have already done session_start(); and initialized $conn
                  
                  $tempArray =  $_SESSION['query2'];
                  var_dump($tempArray);
                  

                  这篇关于使用 PHP SESSION 变量存储 MySQL 查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:没有 mysqli_stmt_get_result() 和 mysqlnd 下一篇:mysqli查询只返回第一行

                  相关文章

                  最新文章

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

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