For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Sunday, March 29, 2015

Binding Where IN Clause in CodeIgniter

Problem:

How to bind multiple and single value in where IN sql clause using CodeIgniter

Solution:

Pass array variable in query

Example:

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'));

Share:

0 comments:

Post a Comment

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights   You have a website and want to test it'...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive