php在SQLite中使用bindParam

时间:2017-12-02 14:03:54

标签: php

当我尝试向sqlite数据库添加内容时,结果始终为false。错误在哪里?我没有异常,所以我认为代码是正确的语法。请帮帮我

public function add(ChatMessage $chatMessage){        
        $stmt = $this->db->prepare('INSERT INTO chatmessage(id,authorName,message) VALUES(:id,:authorName,:message)');

        $stmt->bindParam(':id',$id);
        $stmt->bindParam(':authorName',$authorName);
        $stmt->bindParam(':message',$message);

        $id = $chatMessage->getID();
        $authorName = $chatMessage->getAuthorName();
        $message = $chatMessage->getMessage(); 
        $result = $stmt->execute();

        if($result == false) return false;
        $chatMessage->setID($this->db->lastInsertId());
        $chatMessage->setAuthorName($this->db->lastInsertId());
        $chatMessage->setMessage($this->db->lastInsertId());
        $this->chatMessages[]=$chatMessage;
    }

0 个答案:

没有答案