Problem:
How to bind multiple and single value in where IN sql clause using CodeIgniterSolution:
Pass array variable in queryExample:
Passing single numeric value using array.$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array(1), 'nm123', 'c123'));
Passing multiple numeric value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array(1, 2, 3), 'nm123', 'c123'));
Passing single string value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array('a1'), 'nm123', 'c123'));
Passing multiple string value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array('a1', 'a2', 'a3'), 'nm123', 'c123'));
0 comments:
Post a Comment