我有以下代码:
public function getNotification() {
$sth = $this->dbh->prepare("SELECT n.to_uid as `notif_to_uid`, n.status as `notif_status`, n.time as `notif_time`, u.id as `user_id`, u.name as `user_name` FROM notifications n INNER JOIN users u ON u.id = n.to_uid WHERE u.id = :uid n.type = 'friendrequest'");
$sth->execute(array(
':uid' => $_SESSION['uid']
)
);
if($notifications = $sth->fetchAll(PDO::FETCH_OBJ)) {
foreach($notifications as $notification) {
echo 'New notification ect. ect.';
}
}
}
我的表格如下:
CREATE TABLE `notifications` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from_uid` int(11) NOT NULL,
`to_uid` int(11) NOT NULL,
`type` enum('friendrequest','gameinvite','update') NOT NULL,
`status` enum('unseen','seen') NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(155) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`gender` varchar(255) NOT NULL,
`points` varchar(255) DEFAULT '0',
PRIMARY KEY (`id`)
);
现在它不输出任何东西,并且与db的连接确实有效。
答案 0 :(得分:1)
尝试按
显示查询错误$execute = $sth->execute(array(
':uid' => $_SESSION['uid']
)
);
if(!$execute){
print_r($sth->errorInfo());
}
我看到你在这里输了“AND”或“OR”
WHERE u.id = :uid n.type = 'friendrequest'