我有一个包含 3 个表(成员、船、船类型)的数据库,并且在下面的方法中,其中两个受到影响。我想要列出在会员上注册的所有船只,但代码有问题(至少是 SQL,但我怀疑这还不是全部)。
提前致谢。
船处理程序.php:
public function GetMembersBoats($memberId) {
$query = "SELECT b.boatId, b.length, bt.type
FROM boat AS b
INNER JOIN member AS m
ON b.memberId = m.memberId
WHERE m.memberId = ?
INNER JOIN boatType AS bt
ON b.boatTypeId = bt.boatTypeId
GROUP BY b.boatId";
$stmt = $this->m_db->Prepare($query);
$stmt->bind_param('i', $memberId);
$boats = $this->m_db->GetBoats($stmt);
}
数据库.php:
public function GetBoats($stmt) {
$boats = array(
0 => array(),
1 => array(),
2 => array()
);
$stmt->execute();
$stmt->bind_result($boatId, $length, $type);
while ($stmt->fetch()) {
array_push($boats[0], $boatId);
array_push($boats[1], $length);
array_push($boats[2], $type);
}
$stmt->Close();
return $boats;
}
受影响的表:
- 船: boatId,boatTypeId,长度,memberId
- 船型:船型ID,类型