0

我有一个问题,这是我的控制器的一部分,它为我提供了一个空数组:

$tifos = $model-> select()->setIntegrityCheck(false) 
                -> from(array('t'=>'tifos'), array('*', 'date'=>'DATE(t.created_at)'))
                -> join(array('u'=>'users'), 'u.id=t.users_id', array('username', 'avatar'))
                -> where('status = ?', $status)
                -> order('likes DESC')
                -> limit(10, 0)->query()->fetchAll()
                ;

$model 是扩展 Zend_Db_Table 的类的一个实例。

什么可能导致问题?我正在使用 Zend 1.12。

编辑

好的,这就是我现在得到的,我的 MySQL 查询:

SELECT `t`.*, DATE(`t`.`created_at`) AS `date`, `u`.`username`, `u`.`avatar` FROM `tifos` AS `t` INNER JOIN `users` AS `u` ON `u`.`id`=`t`.`users_id` WHERE (`t`.`status` = 'ok') ORDER BY `t`.`likes` DESC LIMIT 10

我的数据库结构:

CREATE TABLE IF NOT EXISTS `tifos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`users_id` int(11) NOT NULL,
`status` enum('ok','waiting','deleted') NOT NULL DEFAULT 'waiting',
`file` varchar(127) NOT NULL,
`description` varchar(255) NOT NULL,
`likes` int(11) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `users_id` (`users_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;



CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(63) NOT NULL,
`password` varchar(40) NOT NULL,
`email` varchar(63) NOT NULL,
`firstname` varchar(63) NOT NULL,
`lastname` varchar(63) NOT NULL,
`avatar` varchar(64) NOT NULL,
`email_verified` tinyint(1) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`verification_key` varchar(40) NOT NULL,
`newsletter` tinyint(1) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `username` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=28 ;
4

1 回答 1

0

检查某些客户端(如 PMA)中 SQL 语句的结果是什么

$oSql = $model-> select()->setIntegrityCheck(false) 
                -> from(array('t'=>'tifos'), array('*', 'date'=>'DATE(t.created_at)'))
                -> join(array('u'=>'users'), 'u.id=t.users_id', array('username', 'avatar'))
                -> where('status = ?', $status)
                -> order('likes DESC')
                -> limit(10, 0);

// die((string)$oS); //execute sql in mysql client, pma and checks if it is correct

$tifos = $model->fetchAll($oS);
于 2013-08-05T22:16:37.700 回答