我遇到了问题,这是我控制器的一部分,它为我提供了一个空数组:
$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 ;
答案 0 :(得分: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);