首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
PDO MySQL 多次查询同一张表,数据丢失问题
### 问题描述 Swoole HTTP 服务下,PDO MySQL 不同条件多次查询同一张表,第一次为有数据的查询,并赋值打印,第二次为无数据的查询(没有赋值),刷新页面后,输出为false ### Swoole版本,PHP版本,以及操作系统版本信息 Swoole # 4.6.7 PHP # 7.4.20 Centos # 7.7.1908 ### 相关代码 ```php // 查询数据存在 $shopInfo = DbHelper::connection()->table('sys_shop') ->fields(['shop_id', 'shop_status', 'shop_domain', 'shop_domain2', 'shop_domain2_redirect_code']) ->whereOr(['shop_domain' => $domain, 'shop_domain2' => $domain]) ->orderBy(['shop_id' => 'desc']) ->find(); // 首次打印正常输出,第二次开始无数据输出 var_dump($shopInfo); // 查询数据不存在 DbHelper::connection()->table('sys_shop') ->fields(['shop_id', 'shop_status', 'shop_domain', 'shop_domain2', 'shop_domain2_redirect_code']) ->where(['shop_id' => 10]) ->find(); if (empty($shopInfo) || (int)$shopInfo['shop_status'] !== 1) { throw new \Exception('Website Invalid'); } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待多次查询结果不影响其他查询结果,实际上首次访问正常,后面的访问都是获取不到数据,抛出异常 WebSite Invalid
发布于5年前 · 22 次浏览 · 来自
提问
daobin
### 问题描述 Swoole HTTP 服务下,PDO MySQL 不同条件多次查询同一张表,第一次为有数据的查询,并赋值打印,第二次为无数据的查询(没有赋值),刷新页面后,输出为false ### Swoole版本,PHP版本,以及操作系统版本信息 Swoole # 4.6.7 PHP # 7.4.20 Centos # 7.7.1908 ### 相关代码 ```php // 查询数据存在 $shopInfo = DbHelper::connection()->table('sys_shop') ->fields(['shop_id', 'shop_status', 'shop_domain', 'shop_domain2', 'shop_domain2_redirect_code']) ->whereOr(['shop_domain' => $domain, 'shop_domain2' => $domain]) ->orderBy(['shop_id' => 'desc']) ->find(); // 首次打印正常输出,第二次开始无数据输出 var_dump($shopInfo); // 查询数据不存在 DbHelper::connection()->table('sys_shop') ->fields(['shop_id', 'shop_status', 'shop_domain', 'shop_domain2', 'shop_domain2_redirect_code']) ->where(['shop_id' => 10]) ->find(); if (empty($shopInfo) || (int)$shopInfo['shop_status'] !== 1) { throw new \Exception('Website Invalid'); } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待多次查询结果不影响其他查询结果,实际上首次访问正常,后面的访问都是获取不到数据,抛出异常 WebSite Invalid
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
还没有评论!