0

我收到我的 sql 错误“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 ' 附近使用的正确语法?” 在第 4 行

SELECT cm.user_id, chat_message_content, u.firstname FROM chat_message cm JOIN user u ON cm.user_id = u.user_id WHERE cm.chat_id= ?”

模型

function get_chat_messages($chat_id) {
        $query_str = "SELECT cm.user_id, chat_message_content, u.firstname
                      FROM chat_message cm
                      JOIN user u ON cm.user_id = u.user_id
                      WHERE cm.chat_id= ?";
        $results = $this->db->query($query_str, $chat_id);
        return $results;
    }
4

2 回答 2

0

如果它是您要过滤的数据库中的值,请尝试在问号周围加上引号:

$query_str = "SELECT cm.user_id, chat_message_content, u.firstname
                      FROM chat_message cm
                      JOIN user u ON cm.user_id = u.user_id
                      WHERE cm.chat_id= '?'";
于 2013-08-19T17:43:17.550 回答
0

尝试以下操作:

$query_str = "SELECT cm.user_id, chat_message_content, u.firstname
                      FROM chat_message cm
                      JOIN user u ON cm.user_id = u.user_id
                      WHERE cm.chat_id= (?)";
于 2013-08-19T17:47:15.177 回答