Я создаю небольшое веб-приложение, которое позволяет пользователям писать обратную связь в базе данных MySQL. Вот функция, которая заботится о написании обратной связи:Не удается записать в базу данных MySQL PDO
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();
}
комментируемые линии показывают тест, который я сделал, чтобы увидеть, если он писал на БД, и это не так.
Так что проблема в том, что я не получаю сообщение об ошибке. Я уверен, что правильно подключен к базе данных (эта же функция работала над первой ничьей проекта, которая включала гораздо более простой БД).
Я проверил объект $ обратной связи, содержащий все правильные параметры, и это так.
Так в чем же моя ошибка, здесь? Спасибо за вашу помощь.
Ваше заявление '' INSERT INTO'' неверно. '' SET'' используется в '' UPDATE''. Взгляните на http://www.w3schools.com/sql/sql_insert.asp – ub3rst4r
Что касается того, почему нет сообщения об ошибке, '' PDO :: ERRMODE_SILENT'' (http://php.net/manual/en /pdo.error-handling.php) устанавливается по умолчанию – ub3rst4r