我正在构建一个小型网络应用程序,允许用户在 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();
}
注释行显示了我所做的一个测试,看看它是否写在数据库上,但事实并非如此。
所以问题是我没有收到任何错误消息。我确信我已正确连接到数据库(这个相同的函数正在项目的第一次绘制中工作,其中包括一个更简单的数据库)。
我检查了 $feedback 对象包含所有正确的参数,确实如此。
那么我的错误是什么?感谢您的帮助。
最佳答案
好吧,我一定很蠢。我通过更改数据库结构中“_”中的所有“-”解决了该问题。通常最简单的解决方案是有效的。
关于php - 无法在 MySQL PDO 数据库上写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37234265/