我正在使用 php,我正在尝试制作一个页面,您可以在其中查看存储在 mysql 服务器中的公共(public)上传内容。
从我一直在使用的代码开始给我一个错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'public' in 'where clause'
我正在尝试查看我的数据库中有多少行具有“公共(public)”
// Find out how many items are in the table
$p = 'public';
$total = $db->query("SELECT COUNT(*) FROM uploads WHERE world_access = $p")->fetchColumn();
不知道是php还是sql。
// Prepare the paged query
$stmt = $db->prepare('SELECT * FROM uploads WHERE world_access = :y ORDER BY upload_time DESC LIMIT :limit OFFSET :offset');
// Bind the query params
$stmt->bindParam(':y', $p, PDO::PARAM_INT);
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
最佳答案
用引号将 $p
括起来
$total = $db->query("SELECT COUNT(*) FROM uploads WHERE world_access = '$p'")->fetchColumn();
同样在您的 PDO 中,:y
是字符串吗?然后使用 PDO::PARAM_STR
关于php - 在 where 子句中找不到列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582590/