我正在构建一个小型Web应用程序,允许用户在MySQL数据库中编写反馈。这是负责编写反馈的功能:
public function add(Feedback $feedback) {
$query = $this->db->prepare('INSERT INTO feedback SET country = :country, country-other = :countryOther, find-out = :findOut, find-out-other = :findOutOther, what-tour = :whatTour, booking-rating = :bookingRating, booking-comments = :bookingComments, checkin-rating = :checkinRating, checkin-comments = :checkinComments, journey-rating = :journeyRating, journey-comments = :journeyComments, guides-informative-rating = :guidesInformativeRating, guides-informative-comments = :guidesInformativeComments, guides-professional-rating = :guidesProfessionalRating, guides-professional-comments = :guidesProfessionalComments, tour-rating = :tourRating, tour-comments = :tourComments, tour-length = :tourLength, recommendation = :recommendation, comments = :comments');
$query->bindValue(':country', $feedback->country());
$query->bindValue(':countryOther', $feedback->countryOther());
$query->bindValue(':findOut', $feedback->findOut());
$query->bindValue(':findOutOther', $feedback->findOutOther());
$query->bindValue(':whatTour', $feedback->whatTour());
$query->bindValue(':bookingRating', $feedback->bookingRating());
$query->bindValue(':bookingComments', $feedback->bookingComments());
$query->bindValue(':checkinRating', $feedback->checkinRating());
$query->bindValue(':checkinComments', $feedback->checkinComments());
$query->bindValue(':journeyRating', $feedback->journeyRating());
$query->bindValue(':journeyComments', $feedback->journeyComments());
$query->bindValue(':guidesInformativeRating', $feedback->guidesInformativeRating());
$query->bindValue(':guidesInformativeComments', $feedback->guidesInformativeComments());
$query->bindValue(':guidesProfessionalRating', $feedback->guidesProfessionalRating());
$query->bindValue(':guidesProfessionalComments', $feedback->guidesProfessionalComments());
$query->bindValue(':tourRating', $feedback->tourRating());
$query->bindValue(':tourComments', $feedback->tourComments());
$query->bindValue(':tourLength', $feedback->tourLength());
$query->bindValue(':recommendation', $feedback->recommendation());
$query->bindValue(':comments', $feedback->comments());
// $query = $this->db->prepare('INSERT INTO feedback (country) VALUES (:country)');
// $country = $feedback->country();
// echo $country;
// $query->bindParam(':country', $country);
$query->execute();
}
注释行显示我做过的测试,看它是否在DB上写,但事实并非如此。
所以问题是我没有收到任何错误消息。我确信我已正确连接到数据库(同样的功能正在进行项目的第一次绘制,其中包括一个更简单的数据库)。
我检查了$ feedback对象包含所有正确的参数,确实如此。
那么我的错误是什么?谢谢你的帮助。
答案 0 :(得分:0)
好的,我一定很傻。我通过更改所有' - '来解决问题。在' _'在DB结构中。通常最简单的解决方案都有效。