mark mark - 1 month ago 8
MySQL Question

mysql php cannot use "like" as column header

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

Answer Source

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 . "'

        ");