{"id":1274,"date":"2022-08-30T15:15:10","date_gmt":"2022-08-30T15:15:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/zend-db-count-not-working-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:10","modified_gmt":"2022-08-30T15:15:10","slug":"zend-db-count-not-working-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/zend-db-count-not-working-collection-of-common-programming-errors\/","title":{"rendered":"Zend DB &#8211; Count(*) not working-Collection of common programming errors"},"content":{"rendered":"<p>My sql statement is not working with Zend, its complaining about the Count(*) field&#8230; what am I doing wrong?<\/p>\n<pre><code>\/\/ get open\/closed\n$stmt = $db-&gt;query('SELECT status, count(*) as total FROM reported_issues WHERE date_reported &gt;= '.$today.' AND status IN (0,1) GROUP BY status');\nwhile ($row = $stmt-&gt;fetch())\n{\n    switch ($row['status'])\n    {\n        case 0:\n                $totalIssuesToday = $row['total'];\n                break;\n\n        case 1:\n                $totalIssuesClosedToday = $row['total'];\n                break;\n    }\n}\n<\/code><\/pre>\n<p>and the errors&#8230;<\/p>\n<pre><code>Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message\n'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Y' in 'where clause''\nin C:\\xampp\\htdocs\\dating\\trunk\\library\\Zend\\Db\\Statement\\Pdo.php:238\n\nStack trace:\n#0 C:\\xampp\\htdocs\\dating\\trunk\\library\\Zend\\Db\\Statement.php(283): Zend_Db_Statement_Pdo-&gt;_execute(Array)\n#1 C:\\xampp\\htdocs\\dating\\trunk\\library\\Zend\\Db\\Adapter\\Abstract.php(484): Zend_Db_Statement-&gt;execute(Array)\n#2 C:\\xampp\\htdocs\\dating\\trunk\\library\\Zend\\Db\\Adapter\\Pdo\\Abstract.php(235): Zend_Db_Adapter_Abstract-&gt;query('SELECT status, ...', Array)\n#3 C:\\xampp\\htdocs\\dating\\trunk\\html\\siteadmin.php(59): Zend_Db_Adapter_Pdo_Abstract-&gt;query('SELECT status, ...')\n#4 {main} thrown in C:\\xampp\\htdocs\\dating\\trunk\\library\\Zend\\Db\\Statement\\Pdo.php on line 238\n<\/code><\/pre>\n<ol>\n<li>\n<p>The complaint is actually about the <code>WHERE<\/code> &#8212; looks like your <code>$today<\/code> variable does not contain what you think it should. Specifically, since it says:<\/p>\n<pre><code>'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Y' in 'where clause''\n<\/code><\/pre>\n<p>it seems your variable contains a <code>Y<\/code> that shouldn&#8217;t be there. The <code>count<\/code> appears to have nothing to do with the issue.<\/p>\n<\/li>\n<li>\n<p>Aside from what others have noted about the value you have in $today, you really should be using bound parameters with your queries<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:13:40. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>My sql statement is not working with Zend, its complaining about the Count(*) field&#8230; what am I doing wrong? \/\/ get open\/closed $stmt = $db-&gt;query(&#8216;SELECT status, count(*) as total FROM reported_issues WHERE date_reported &gt;= &#8216;.$today.&#8217; AND status IN (0,1) GROUP BY status&#8217;); while ($row = $stmt-&gt;fetch()) { switch ($row[&#8216;status&#8217;]) { case 0: $totalIssuesToday = $row[&#8216;total&#8217;]; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1274","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1274"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1274\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}