php - PHP SQLite - Not returning correct count of match
问题描述
I am using PHP lite to search for a matching row like this...
$count = $db->exec("SELECT * FROM users WHERE userid = '34534fgr'");
echo $count;
But my count is returning 1 every time, even when the value does not exist.
Am I searching incorrectly?
解决方案
Am I searching incorrectly?
对。提示:调试时,使用var_dump
代替echo
,它会帮助你在这里看到问题,因为它会打印bool(true);
而不是int(1)
or string("1")
,因为 PDO::exec() 返回一个布尔值。
这是您尝试做的事情的方法:
$count = $db->query("SELECT COUNT(*) FROM users WHERE userid = '34534fgr'",PDO::FETCH_NUM)->fetch()[0];
推荐阅读
- amazon-web-services - 通过 CDK 创建动态 S3 存储桶名称
- kubernetes - Maistra ServiceMeshControlPlane 和 Mesh 在 OpenShift4 上的同一命名空间/项目中
- javascript - 试图弄清楚如何让我的 MongoDB 数据库显示属于某个用户的项目(按 ID)
- reactjs - 如何将元素导入另一个 React 组件?
- flutter - 为什么 DartPad 给出了与 Android studio 不同的结果?
- react-native - 错误:无法从 C:\**\node_modules\cipher-base\index.js 解析模块流:在项目中找不到流
- r - 当 x 变量的值超过 10 个时如何一次绘制箱线图
- numpy - 带列表的 Numpy 切片
- python - 检索熊猫数据框的名称
- python - 是否可以将两个冻结图(.pb)一个一个连接起来?