doulong4169 2017-08-23 05:16
浏览 50
已采纳

mysql php不能使用“like”作为列标题

I am using codeigniter to build an app and I am really far in the code.

I have a table with column headers id, page, user and like. Now the problem is, in the mysql query, I realised I cant use the word like for the column name as its a sql keyword I belive.

I can't change the column name from like to something else because it would mean changing 100s of lines of php code.

Is there something that i can do to overcome the clash of the world like?

here is what I mean

$like_variable = 100;
$query =  $this->db->query("SELECT * FROM `table_name` 

            WHERE id ='" . $qry . "' AND 

            page = '" . $_SESSION['p_id'] . "' AND 

            user_id = '" . $_SESSION['user_id'] . "' AND

            like = '" . $like_variable . "'

            ");
            // i think i cant use the world like above but I cant change the column header

Any solutions would be much appreciated thanks in advance

  • 写回答

2条回答 默认 最新

  • dongqiao8502 2017-08-23 05:20
    关注

    Change like to:

    `like`
    

    Result:

    $like_variable = 100;
    $query =  $this->db->query("SELECT * FROM `table_name` 
    
            WHERE id ='" . $qry . "' AND 
    
            page = '" . $_SESSION['p_id'] . "' AND 
    
            user_id = '" . $_SESSION['user_id'] . "' AND
    
            `like` = '" . $like_variable . "'
    
            ");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码