{"id":1227,"date":"2022-08-30T15:14:30","date_gmt":"2022-08-30T15:14:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/zend-framework-2-where-clause-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:14:30","modified_gmt":"2022-08-30T15:14:30","slug":"zend-framework-2-where-clause-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/zend-framework-2-where-clause-collection-of-common-programming-errors\/","title":{"rendered":"Zend Framework 2 &#8211; Where Clause-Collection of common programming errors"},"content":{"rendered":"<p>I would like to add a where clause with this method.<\/p>\n<pre><code>public function fetchAll()\n{\n    $resultSet = $this-&gt;select();\n    return $resultSet;\n}\n<\/code><\/pre>\n<p>I have added like this.<\/p>\n<pre><code>public function fetchAll()\n{\n    $resultSet = $this-&gt;select();\n    $resultSet-&gt;where(\"status = ?\", 1);\n    return $resultSet;\n}\n<\/code><\/pre>\n<p>But, it shown the below error.<\/p>\n<blockquote>\n<p>Fatal error: Call to undefined method Zend\\Db\\ResultSet\\ResultSet::where()<\/p>\n<\/blockquote>\n<p>Could you please help me to add WHERE, OR WHERE, GROUP and ORDER with above mentioned method.<\/p>\n<ol>\n<li>\n<p>Hopefully this will help you out:<\/p>\n<pre><code>    public function Profile($accountid)\n    {\n        $result = $this-&gt;select(function (Select $select) use ($accountid) {\n            $select\n                -&gt;columns(array(\n                    'datefrom',\n                    'available',\n                    'used',\n                    'details'\n                ))\n                -&gt;where($this-&gt;adapter-&gt;getPlatform()-&gt;quoteIdentifier('accountid') . ' = ' . $this-&gt;adapter-&gt;getPlatform()-&gt;quoteValue($accountid));\n        });\n\n        $row = $result-&gt;current();\n\n        if (!$row) {\n            throw new \\Exception('could_not_find_row');\n        }\n\n        return $row;\n    }\n<\/code><\/pre>\n<\/li>\n<li>\n<p>You can also do <code>$sql-&gt;select()-&gt;where(array('status' =&gt; 1))<\/code> or <code>$table-&gt;select(array('status' =&gt; 1))<\/code> (annoying, wish they used the same syntax).<\/p>\n<p>You pass where an associative array with the mapping <code>column =&gt; value<\/code> (and since it&#8217;s an array you can give it multiple clauses). Diemuzi&#8217;s way is good for complex identifiers but this is a more readable way for simple comparison.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:10:52. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I would like to add a where clause with this method. public function fetchAll() { $resultSet = $this-&gt;select(); return $resultSet; } I have added like this. public function fetchAll() { $resultSet = $this-&gt;select(); $resultSet-&gt;where(&#8220;status = ?&#8221;, 1); return $resultSet; } But, it shown the below error. Fatal error: Call to undefined method Zend\\Db\\ResultSet\\ResultSet::where() Could you [&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,8],"tags":[],"class_list":["post-1227","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-zend-framework"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1227","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=1227"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":8883,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions\/8883"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}