简体   繁体   English

Zend | Db \\ Sql | Expression在Zend SL语句中不起作用

[英]Zend|Db\Sql|Expression not working in Zend SL statement

I cannot get valid data from the Zend Framework sql statements shown below which I use in php and is called from an angularjs script: 我无法从下面显示的Zend Framework sql语句中获取有效数据,该数据在php中使用,并且是从angularjs脚本调用的:

    $where = new Where ();   
    $where->greaterThanOrEqualTo('user_id', '963');  
    $resultSet = $this->tableGateway->select(function(Select $select) use
    ($where){
    $select->where($where);  
      $select->columns(array('date_added','datemonth' => new \Zend\Db\Sql\Expression("MONTH('date_added')"), 'count' => new \Zend\Db\Sql\Expression("COUNT(*)")));
    $select->group('datemonth');
    return $resultSet;

My angular js script dumps the data as shown below: 我的angular js脚本转储数据,如下所示:

    success(function(response) {

            for(var i in response.response) {
                var tc = response.response[i];
                alert("userdata date_added=" + tc['date_added'] + " datemonth=" + tc['datemonth'] + " count=" + tc["count"]);
         }

And the results are as shown: 结果如下:

userdata date_added=2014-05-22 20:00:27 datemonth=undefined count=undefined

Can anyone tell me if I am using the Zend\\Db\\Sql\\Expression incorrectly or why isn't the datemonth and count not coming back correctly? 谁能告诉我我是否正确使用了Zend \\ Db \\ Sql \\ Expression或为什么datemonth和count不能正确返回? I want to be able to get the number of records by month. 我希望能够按月获取记录数。

Update: I was able to dump the putput from the server and it shows all the fields on the database record but none for the fields created in the Zend Expression functions for datemonth and count. 更新:我能够从服务器转储putput,它显示了数据库记录中的所有字段,但没有显示在Zend Expression函数中为datemonth和count创建的字段。 Below is the dump. 下面是转储。 Anyone know why the Expression fields aren't in the dump? 有人知道为什么表达式字段不在转储中吗?

Php Code: 邮递区号:

       echo "Resultset = " . $resultSet->date_added;

Dump of above code: 上面的代码转储:

       Resultset = {"success":true,"response":[{"inputFilter":null,"user_id":0,"instagram_user_id":"","fbid":"","instagram_username":null, "full_name":"","profile_image":"","bio":"","website":"","media_count":0,"following_count":0,"followed_by_count":0,"like_count":0,"recommend_count":0,"date_added":"2014-05-22 20:00:27","flag_count":0,"date_updated":"","email":"","password":"","access_token":"","premium":0,"login_attempts":0,"status":0,"request_count":0,"request_date":""}]}

You may try this to preview your SQL query: 您可以尝试以下方法预览您的SQL查询:

$sql = new \Zend\Db\Sql\Sql($this->tableGateway->adapter);
echo $sql->getSqlStringForSqlObject($select);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM