mysql 查session,使用PHP SESSION变量存储MySQL查询结果
发布日期:2022-02-19 00:02:17 浏览次数:15 分类:技术文章

本文共 1229 字,大约阅读时间需要 4 分钟。

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 "

error

"; //This line gets executed

} else {

echo "

works!

";

}

} else {

echo "

array not set

";

}

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);

转载地址:https://blog.csdn.net/weixin_34236334/article/details/118814960 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java swing点击文字打开网站,Java Swing;单击按钮后如何显示文本
下一篇:jackson json java对象,使用Jackson将Java对象转换为JSON

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月07日 02时30分18秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

spring boot 与 Ant Design of Vue 实现获取用户列表(二十七) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增用户(二十八) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改用户(二十九) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除用户(三十) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系登录的实现(三十一) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系获取用户信息的实现(三十二) 2019-04-27
Druid连接池实现自定义场景的多数据库的连接 2019-04-27
CentOs7命令行(静默)的方式安装oracle数据库 2019-04-27
基于VMware安装CentOs7的镜像 2019-04-27
PL/SQL数据库管理工具的使用 2019-04-27
带你玩转属于自己的spring-boot-starter系列(一) 2019-04-27
带你玩转属于自己自己的spring-boot-starter系列(二) 2019-04-27
带你玩转属于自己的spring-boot-starter系列(三) 2019-04-27
基于SnowFlake算法如何让分库分表中不同的ID落在同一个库的算法的实现 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分库解决方案(二) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分表解决方案(一) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之关联查询解决方案(三) 2019-04-27
Linux文件管理参考 2019-04-27
FTP文件管理项目(本地云)项目日报(一) 2019-04-27
FTP文件管理项目(本地云)项目日报(二) 2019-04-27