dpwdsmbvm496180204 2016-05-15 03:32
浏览 25
已采纳

无法在MySQL PDO数据库上写[重复]

This question already has an answer here:

I am building a small web app that allows users to write a feedback in a MySQL database. Here is the function that takes care of writing the feedback:

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();
    }

Commented lines show a test I did to see if it was writing on DB, and it's not.

So the problem is that I don't get any error message. I am sure I am correctly connected to the database (this same function was working on the first draw of the project, which included a much simpler DB).

I checked the $feedback object contains all the correct parameters, and it does.

So what is my mistake, here? Thanks for your help.

</div>
  • 写回答

1条回答 默认 最新

  • douzi0609 2016-05-15 04:17
    关注

    OK I must be quite stupid. I solved the problem by changing all '-' in '_' in the DB structure. Usually the simplest solutions work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100