gpt4 book ai didi

php - Zend DB - 计数(*)不工作

转载 作者:行者123 更新时间:2023-11-30 23:56:31 25 4
gpt4 key购买 nike

我的 sql 语句不适用于 Zend,它提示 Count(*) 字段...我做错了什么?

// get open/closed
$stmt = $db->query('SELECT status, count(*) as total FROM reported_issues WHERE date_reported >= '.$today.' AND status IN (0,1) GROUP BY status');
while ($row = $stmt->fetch())
{
switch ($row['status'])
{
case 0:
$totalIssuesToday = $row['total'];
break;

case 1:
$totalIssuesClosedToday = $row['total'];
break;
}
}

和错误...

Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message
'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Y' in 'where clause''
in C:\xampp\htdocs\dating\trunk\library\Zend\Db\Statement\Pdo.php:238

Stack trace:
#0 C:\xampp\htdocs\dating\trunk\library\Zend\Db\Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\xampp\htdocs\dating\trunk\library\Zend\Db\Adapter\Abstract.php(484): Zend_Db_Statement->execute(Array)
#2 C:\xampp\htdocs\dating\trunk\library\Zend\Db\Adapter\Pdo\Abstract.php(235): Zend_Db_Adapter_Abstract->query('SELECT status, ...', Array)
#3 C:\xampp\htdocs\dating\trunk\html\siteadmin.php(59): Zend_Db_Adapter_Pdo_Abstract->query('SELECT status, ...')
#4 {main} thrown in C:\xampp\htdocs\dating\trunk\library\Zend\Db\Statement\Pdo.php on line 238

最佳答案

除了其他人注意到您在 $today 中的值(value)之外,您确实应该在查询中使用绑定(bind)参数

<?php

$stmt = $db->query(
"SELECT status, count(*) as total
FROM reported_issues
WHERE date_reported >= ?
AND status IN (0,1)
GROUP BY status"
,array( $today )
);

关于php - Zend DB - 计数(*)不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/956339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com