php - 无法在 MySQL PDO 数据库上写入

标签 php mysql pdo

我正在构建一个小型网络应用程序,允许用户在 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/

相关文章:

php 从 mysql 数据库进行查询时出现错误,如 'where clause' 中的未知列

php - 使用 CURL 向 Web 服务器发送 XML post 请求

mysql - 将 R 连接到在 Amazon ec2 Ubuntu 计算机上运行的 MySQL 时出错

php - CSV 输出显示整个 HTML 页面

php - mysql 或 sqlite 以及设计选择的安全性

php - SQL中的控制流问题

php - 我应该检查 pdo php 中执行操作的返回值吗

php - 如何使用 PHP PDO 和 MySQL 对数组中的对象进行分组?

php - 是否有生成格式良好的表单的标准?

php/mysql 不能同时运行同一个文件两次