'Parameter Binding in CodeIgniter 3.1 Query Builder

I have a query

$column = 1234;
$sql = "SELECT * FROM TABLE WHERE COLUMN = ?";
$result = $this->db->query($sql,[$column])->row();

which works completely fine But when i have union clause i have to pass the parameter twice

$sql = "SELECT * FROM TABLE1 WHERE COLUMN = ?
       UNION
       SELECT * FROM TABLE2 WHERE COLUMN = ?";
$result = $this->db->query($sql,[$column,$column])->result();

Do we have something like below code to achieve the above result where i could pass only one value since both of them requires same value.

$sql = "SELECT * FROM TABLE1 WHERE COLUMN = :column
       UNION
       SELECT * FROM TABLE2 WHERE COLUMN = :column";
$result = $this->db->query($sql,['column' => $column])->result();


Solution 1:[1]

Well you can just use :

$column = 1234;
$sql = "SELECT * FROM TABLE1 WHERE COLUMN = " . $column . "
       UNION
       SELECT * FROM TABLE2 WHERE COLUMN = " . $column . ";
$result = $sql->result();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mentega Terbang