쿼리 빌더 클래스 Query Builder Class

CodeIgniter 는 쿼리 빌더 클래스를 사용합니다. 이 패턴은 정보의 추출,삽입, 업데이트를 최소한의 코드로 수행할 수 있게 해줍니다. 때에 따라서 한두 줄의 코드만으로 원하는 처리를 할 수도 있습니다. 또한, 각 데이터베이스 테이블이 그 자신의 클래스에 반드시 존재할 필요도 없습니다. CodeIgniter 는 보다 간단한 인터페이스를 제공합니다.

단순성 보다 더 중요한 장점은 바로 데이터베이스에 독립된 프로그램을 만들 수 있다는 점입니다. 액티브레코드는 사용하는 데이터베이스 어댑터에 맞게 쿼리를 자동으로 생성합니다. 게다가, 자동으로 값들을 이스케이프(escape)하기 때문에 보다 안전한 쿼리를 만들어 냅니다.

Note

쿼리를 직접 작성하여 사용하고자한다면, 데이터베이스 설정파일에서 액티브레코드를 비활성(disable)화 시킬수 있습니다. 그렇게 하면 코어 데이터베이스 라이브러리및 어댑터를 사용할 때 리소스를 절약할 수 있습니다.

데이터 조회 Selecting Data

다음 함수들은 SQL SELECT 문을 생성할 수 있도록 해줍니다.

$this->db->get()

조회 쿼리를 수행하며 결과를 리턴합니다. 함수 그 자체를 사용하면 모든 레코드를 가져오는 쿼리를 자동으로 실행합니다:

$query = $this->db->get('mytable');  // Produces: SELECT * FROM mytable

두 번째, 세 번째 파라미터는 리미트(limit)와 오프셋(offset)을 설정하는데 사용됩니다:

$query = $this->db->get('mytable', 10, 20);

// Executes: SELECT * FROM mytable LIMIT 20, 10
// (in MySQL. Other databases have slightly different syntax)

위 함수에서는 결과를 $query변수에 할당하며, 아래와 같이 활용할 수 있습니다:

$query = $this->db->get('mytable');

foreach ($query->result() as $row)
{
        echo $row->title;
}

쿼리 결과생성(result functions) 페이지를 참조하시면 좀 더 자세한 정보가 있습니다.

$this->db->get_compiled_select()

셀렉트 쿼리를 $this->db->get()와 같이 컴파일하지만, 쿼리를 실행하지는 않습니다. 이 함수는 단지 SQL 쿼리를 문자열로 반환합니다.

예제:

$sql = $this->db->get_compiled_select('mytable');
echo $sql;

// Prints string: SELECT * FROM mytable

두 번째 파라미터는 쿼리 빌더를 재설정할지 결정합니다. (기본적으로 $this->db->get()를 사용하는 것처럼 재설정됩니다):

echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);

// Prints string: SELECT * FROM mytable LIMIT 20, 10
// (in MySQL. Other databases have slightly different syntax)

echo $this->db->select('title, content, date')->get_compiled_select();

// Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10

위의 예제에서 알 수 있는 중요한 것은, 두 번째 쿼리는 $this->db->from() 를 사용하지 않았고, 테이블명을 첫 번째 파라미터로 전달하지 않았다는 것입니다. 이 결과에 대한 이유는 쿼리가 값을 초기화하는 $this->db->get() 를 사용하지 않았기 때문입니다.

$this->db->get_where()

db->where() 함수 대신 “where” 절을 두 번째 파라미터로 사용할 수 있다는 점을 빼면 위의 함수와 동일합니다:

$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);

아래쪽에 있는 where 함수의 내용을 보시면 더 자세한 정보를 얻으실 수 있습니다.

Note

get_where() 함수의 이전 버전인 getwhere()는 제거되었습니다.

$this->db->select()

쿼리에서 SELECT 부분을 직접 입력할 수 있도록 해 줍니다:

$this->db->select('title, content, date');
$query = $this->db->get('mytable');

// Executes: SELECT title, content, date FROM mytable

Note

전부(*) 를 조회할 때는 이 함수가 필요없습니다. 파라미터가 생략되면 CodeIgniter 는 자동으로 ‘SELECT *’ 를 수행합니다.

$this->db->select() 함수에서는 옵션으로 두 번째 파라미터를 설정할 수 있습니다. 만약 FALSE 로 설정하면 CodeIgniter 는 필드나 테이블명을 백틱(`) 으로 감싸 보호하지 않습니다. 복잡한 select 문을 사용할 때 이것이 유용합니다.

$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');

$this->db->select_max()

SELECT MAX(field) 부분을 사용할 수 있게 합니다. 두 번째 파라미터를 사용하면 결과값의 필드명을 다른 이름으로 바꿀 수 있습니다.

$this->db->select_max('age');
$query = $this->db->get('members');  // Produces: SELECT MAX(age) as age FROM members

$this->db->select_max('age', 'member_age');
$query = $this->db->get('members'); // Produces: SELECT MAX(age) as member_age FROM members

$this->db->select_min()

“SELECT MIN(field)” 부분을 사용할 수 있게 합니다.select_max()와 같이, 두 번째 파라미터를 사용하면 결과값의 필드명을 다른 이름으로 바꿀 수 있습니다.

$this->db->select_min('age');
$query = $this->db->get('members'); // Produces: SELECT MIN(age) as age FROM members

$this->db->select_avg()

“SELECT AVG(field)” 부분을 사용할 수 있게 합니다.select_max()와 같이, 두 번째 파라미터를 사용하면 결과값의 필드명을 다른 이름으로 바꿀 수 있습니다.

$this->db->select_avg('age');
$query = $this->db->get('members'); // Produces: SELECT AVG(age) as age FROM members

$this->db->select_sum()

“SELECT SUM(field)” 부분을 사용할 수 있게 합니다.select_max()와 같이, 두 번째 파라미터를 사용하면 결과값의 필드명을 다른 이름으로 바꿀 수 있습니다.

$this->db->select_sum('age');
$query = $this->db->get('members'); // Produces: SELECT SUM(age) as age FROM members

$this->db->from()

FROM 부분을 사용할 수 있게 합니다:

$this->db->select('title, content, date');
$this->db->from('mytable');
$query = $this->db->get();  // Produces: SELECT title, content, date FROM mytable

Note

앞서 보여준대로, FROM 부분은 $this->db->get() 함수에서 정의해줄 수 있습니다. 그러니까 위 함수를이용하거나 말거나는 당신의 선택입니다.

$this->db->join()

JOIN 부분을 사용할 수 있게 해줍니다:

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');
$query = $this->db->get();

// Produces:
// SELECT * FROM blogs JOIN comments ON comments.id = blogs.id

여러 개의 조인을 단일 쿼리에 사용할 경우 여러 개의 함수 호출 (function calls)을 사용할 수 있습니다.

기본 조인(JOIN)외의 조인을 할 때는 세 번째 파라미터를 사용할 수 있습니다. 옵션은 다음과 같습니다: left, right, outer, inner, left outer, and right outer.

$this->db->join('comments', 'comments.id = blogs.id', 'left');
// Produces: LEFT JOIN comments ON comments.id = blogs.id

Looking for Specific Data

$this->db->where()

이 함수는 4가지중 한 가지 방법을 사용하여 WHERE 절을 설정할 수 있게 합니다:

Note

이 함수로 전달되는 모든 변수는 자동으로 이스케이프 되어 안전한 쿼리를 생성합니다.

  1. 단순 키/값 방법:

    $this->db->where('name', $name); // Produces: WHERE name = 'Joe'
    

    같다(=) 부분을 자동으로 추가해줍니다.

    이 방법을 여러 번 사용하면 모두 AND 로 연결됩니다:

    $this->db->where('name', $name);
    $this->db->where('title', $title);
    $this->db->where('status', $status);
    // WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
    
  2. 사용자 키/값 방법:

    첫 번째 파라미터에 연산기호를 삽입하여 원하는 쿼리를 만들수 있습니다:

    $this->db->where('name !=', $name);
    $this->db->where('id <', $id); // Produces: WHERE name != 'Joe' AND id < 45
    
  3. 연관배열 방법:

    $array = array('name' => $name, 'title' => $title, 'status' => $status);
    $this->db->where($array);
    // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
    

    아래와 같이 직접 연산기호를 사용할 수도 있습니다:

    $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
    $this->db->where($array);
    
  4. 사용자 문자열 방법:

    아래와 같이 Where 절을 직접 입력할 수도 있습니다:

    $where = "name='Joe' AND status='boss' OR status='active'";
    $this->db->where($where);
    

$this->db->where() 에는 세 번째 파라미터가 옵션으로 제공됩니다. 이 파라미터를 FALSE 로하면, CodeIgniter 는 필드나 테이블명을 백틱(`) 으로 감싸 보호하지 않습니다.

$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);

$this->db->or_where()

여러 개의 조건들이 OR 로 연결되는 것을 제외하면 본 함수는 위의 함수와 동일합니다:

$this->db->where('name !=', $name);
$this->db->or_where('id >', $id);  // Produces: WHERE name != 'Joe' OR id > 50

Note

or_where() 의 이전 버전인 orwhere()는 제거되었습니다.

$this->db->where_in()

WHERE 절의 IN (‘item’, ‘item’) 부분을 생성하며 필요한 경우 AND 로 연결해줍니다.

$names = array('Frank', 'Todd', 'James');
$this->db->where_in('username', $names);
// Produces: WHERE username IN ('Frank', 'Todd', 'James')

$this->db->or_where_in()

WHERE 절의 IN (‘item’, ‘item’) 부분을 생성하며 필요한 경우 OR 로 연결해줍니다.

$names = array('Frank', 'Todd', 'James');
$this->db->or_where_in('username', $names);
// Produces: OR username IN ('Frank', 'Todd', 'James')

$this->db->where_not_in()

WHERE 절의 NOT IN (‘item’, ‘item’) 부분을 생성하며 필요한경우 AND 로 연결해줍니다.

$names = array('Frank', 'Todd', 'James');
$this->db->where_not_in('username', $names);
// Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')

$this->db->or_where_not_in()

WHERE 절의 NOT IN (‘item’, ‘item’) 부분을 생성하며 필요한경우 OR 로 연결해줍니다.

$names = array('Frank', 'Todd', 'James');
$this->db->or_where_not_in('username', $names);
// Produces: OR username NOT IN ('Frank', 'Todd', 'James')

Looking for Similar Data

$this->db->like()

이 함수는 LIKE 절을 생성해줍니다. 검색시에 유용합니다.

Note

전달된 모든 값은 자동으로 이스케이프 됩니다.

  1. 단순 키/값 방법:

    $this->db->like('title', 'match');
    // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
    

    이 함수를 여러 번 호출하면 각각을 AND 로 연결해줍니다:

    $this->db->like('title', 'match');
    $this->db->like('body', 'match');
    // WHERE `title` LIKE '%match%' ESCAPE '!' AND  `body` LIKE '%match% ESCAPE '!'
    

    like 절에서 와일드카드(%)를 사용해야 한다면 옵션인 세 번째 파라미터를 사용할 수 있습니다. 옵션은 다음과 같습니다: ‘before’, ‘after’, ‘both’ (기본값).

    $this->db->like('title', 'match', 'before');    // Produces: WHERE `title` LIKE '%match' ESCAPE '!'
    $this->db->like('title', 'match', 'after');     // Produces: WHERE `title` LIKE 'match%' ESCAPE '!'
    $this->db->like('title', 'match', 'both');      // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
    
  2. 연관배열 방법:

    $array = array('title' => $match, 'page1' => $match, 'page2' => $match);
    $this->db->like($array);
    // WHERE `title` LIKE '%match%' ESCAPE '!' AND  `page1` LIKE '%match%' ESCAPE '!' AND  `page2` LIKE '%match%' ESCAPE '!'
    

$this->db->or_like()

본 함수는 여러 개의 조건들이 OR 로 연결된 경우를 제외하고는 위 함수와 같습니다:

$this->db->like('title', 'match'); $this->db->or_like('body', $match);
// WHERE `title` LIKE '%match%' ESCAPE '!' OR  `body` LIKE '%match%' ESCAPE '!'

Note

or_like() 의 이전 버전인 orlike()는 제거 되었습니다.

$this->db->not_like()

NOT LIKE 문을 생성한다는 점을 제외하면 like() 함수와 완전히 동일합니다:

$this->db->not_like('title', 'match');  // WHERE `title` NOT LIKE '%match% ESCAPE '!'

$this->db->or_not_like()

여러 개의 조건들이 OR 로 연결된다는점을 제외하면 not_like() 함수와 같습니다:

$this->db->like('title', 'match');
$this->db->or_not_like('body', 'match');
// WHERE `title` LIKE '%match% OR  `body` NOT LIKE '%match%' ESCAPE '!'

$this->db->group_by()

GROUP BY 부분을 생성합니다:

$this->db->group_by("title"); // Produces: GROUP BY title

여러 개의 값을 전달하기 위해서 배열도 사용할 수 있습니다:

$this->db->group_by(array("title", "date"));  // Produces: GROUP BY title, date

Note

group_by() 의 이전 버전인 groupby() 는 제거되었습니다.

$this->db->distinct()

쿼리에 “DISTINCT” 키워드를 추가합니다.

$this->db->distinct();
$this->db->get('table'); // Produces: SELECT DISTINCT * FROM table

$this->db->having()

HAVING 부분을 생성합니다. 하나의 파라미터를 사용할 수도 있고 두 개의 파라미터를 사용할 수도 있습니다:

$this->db->having('user_id = 45');  // Produces: HAVING user_id = 45
$this->db->having('user_id',  45);  // Produces: HAVING user_id = 45

여러 개의 값을 전달하기 위해서 배열도 사용할 수 있습니다:

$this->db->having(array('title =' => 'My Title', 'id <' => $id));
// Produces: HAVING title = 'My Title', id < 45

CodeIgniter 자동으로 쿼리를 이스케이프 하는 데이터베이스(ex:Mysql)를 사용하고 있고 이 자동 이스케이프를 끄고싶다면, 세 번째 파라미터를 FALSE 로 설정합니다. 아래 예제를 봐주세요.

$this->db->having('user_id',  45);  // Produces: HAVING `user_id` = 45 in some databases such as MySQL
$this->db->having('user_id',  45, FALSE);  // Produces: HAVING user_id = 45

$this->db->or_having()

여러 조건을 “OR” 로 연결한다는 점을 제외하면 having()과 같습니다.

Ordering results

$this->db->order_by()

ORDER BY 부분을 생성합니다.

첫 번째 파라미터는 정렬 기준이 되는 컬럼명입니다.

두 번째 파라미터는 정렬 방향입니다. 정렬 방향은 ASC, DESC, RANDOM 이 있습니다.

$this->db->order_by('title', 'DESC');
// Produces: ORDER BY `title` DESC

첫 번째 파라미터로 직접 문자열을 입력할 수 있습니다:

$this->db->order_by('title DESC, name ASC');
// Produces: ORDER BY `title` DESC, `name` ASC

아니면 함수를 여러 번 호출하여 여러 필드에 대한 정렬을 수행할 수 있습니다.

$this->db->order_by('title', 'DESC');
$this->db->order_by('name', 'ASC');
// Produces: ORDER BY `title` DESC, `name` ASC

RANDOM 방향 옵션을 선택하면, 숫자 시드 값을 지정하지 않는다면, 첫 번째 파라미터는 무시될 것입니다.

$this->db->order_by('title', 'RANDOM');
// Produces: ORDER BY RAND()

$this->db->order_by(42, 'RANDOM');
// Produces: ORDER BY RAND(42)

Note

order_by() 의 이전 버전인 orderby()는 제거되었습니다.

Note

랜덤(random)정렬은 현재 Oracle, MSSQL 에서는 사용할 수 없습니다. 그러므로 해당 데이터베이스사용시 random은 자동으로 ASC 로 설정됩니다.

Limiting or Counting Results

$this->db->limit()

쿼리 결과로 리턴받을 열의 개수를 설정할 때 사용합니다:

$this->db->limit(10);  // Produces: LIMIT 10

두 번째 파라미터는 오프셋을 설정할 때 사용합니다.

$this->db->limit(10, 20);  // Produces: LIMIT 20, 10 (in MySQL.  Other databases have slightly different syntax)

$this->db->count_all_results()

특정 액티브레코드 쿼리를 통해 적용될 레코드의 수를 확인하도록 해줍니다. 쿼리는 where(), or_where(), like(), or_like() 등과 같은 액티브 레코드 한정자들을 허용합니다. 예제:

echo $this->db->count_all_results('my_table');  // Produces an integer, like 25
$this->db->like('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results(); // Produces an integer, like 17

이 함수도 select() 에 값을 전달해도 초기화되버립니다. 만약에 유지하고 싶으시다면, FALSE 값을 두 번째 파라미터로 전달해주세요:

echo $this->db->count_all_results('my_table', FALSE);

$this->db->count_all()

특정 테이블의 레코드수를 리턴합니다. 첫 번째 파라미터에는 테이블명이 들어갑니다 예제:

echo $this->db->count_all('my_table');  // Produces an integer, like 25

Query grouping

쿼리 그루핑은 WHERE 절에 괄호를 추가하여 그룹을 생성할 수 있게 합니다. WHERE 절에 복잡한 쿼리를 생성 가능하게 합니다. 중첩된 그룹도 지원됩니다. 예제:

$this->db->select('*')->from('my_table')
        ->group_start()
                ->where('a', 'a')
                ->or_group_start()
                        ->where('b', 'b')
                        ->where('c', 'c')
                ->group_end()
        ->group_end()
        ->where('d', 'd')
->get();

// Generates:
// SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'

Note

그룹은 균형을 이루어야 합니다. 모든 group_start() 는 group_end() 와 함께 쓰여져야 합니다.

$this->db->group_start()

쿼리의 WHERE 절에 여는 괄호를 더하여 현재 그룹을 시작합니다.

$this->db->or_group_start()

쿼리의 WHERE 절에 여는 괄호를 더하여 현재 그룹을 시작합니다. ‘OR’ 으로 중간을 연결합니다.

$this->db->not_group_start()

쿼리의 WHERE 절에 여는 괄호를 더하여 현재 그룹을 시작합니다. ‘NOT’ 으로 중간을 연결합니다.

$this->db->or_not_group_start()

쿼리의 WHERE 절에 여는 괄호를 더하여 현재 그룹을 시작합니다. ‘OR NOT’ 으로 중간을 연결합니다.

$this->db->group_end()

쿼리의 WHERE 절에 닫는 괄호를 더하여 현재 그룹을 닫습니다.

Inserting Data

$this->db->insert()

당신이 제공한 데이터를 가지고 insert 쿼리를 생성한 후 실행합니다. 이때 배열 혹은 객체를 사용하여 데이터를 제공합니다. 다음은 배열을 사용한 예입니다:

$data = array(
        'title' => 'My title',
        'name' => 'My Name',
        'date' => 'My date'
);

$this->db->insert('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

첫 번째 파라미터는 테이블명, 두 번째 파라미터는 필드명과 값을 포함한 연관배열 입니다.

다음은 객체를 사용한 예제입니다:

/*
class Myclass {
        public $title = 'My Title';
        public $content = 'My Content';
        public $date = 'My Date';
}
*/

$object = new Myclass;
$this->db->insert('mytable', $object);
// Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')

첫 번째 파라미터는 테이블 명이며, 두 번째 파라미터는 값에 대한 객체입니다.

Note

전달된 모든 값은 자동으로 이스케이프되어 보다 안전한 쿼리로 생성됩니다.

$this->db->get_compiled_insert()

$this->db->insert() 와 같이 insert 쿼리를 생성하지만, 그 쿼리를 실행하지는 않습니다. 이 함수는 쿼리를 단지 문자열로 만들어주는 것입니다.

예제:

$data = array(
        'title' => 'My title',
        'name'  => 'My Name',
        'date'  => 'My date'
);

$sql = $this->db->set($data)->get_compiled_insert('mytable');
echo $sql;

// Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

두 번째 파라미터는 쿼리 빌더 쿼리를 재설정하게 할지 결정합니다. ( 기본적으로 $this->db->insert() 입니다):

echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);

// Produces string: INSERT INTO mytable (title) VALUES ('My Title')

echo $this->db->set('content', 'My Content')->get_compiled_insert();

// Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')

The key thing to notice in the above example is that the second query did not utlize $this->db->from() nor did it pass a table name into the first parameter. The reason this worked is because the query has not been executed using $this->db->insert() which resets values or reset directly using $this->db->reset_query().

Note

This method doesn’t work for batched inserts.

$this->db->insert_batch()

제공된 데이터를 가지고 Insert 쿼리를 생성한 후 수행합니다. 파라미터로 배열이나 객체를 사용할 수 있습니다:

$data = array(
        array(
                'title' => 'My title',
                'name' => 'My Name',
                'date' => 'My date'
        ),
        array(
                'title' => 'Another title',
                'name' => 'Another Name',
                'date' => 'Another date'
        )
);

$this->db->insert_batch('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'),  ('Another title', 'Another name', 'Another date')

첫 번째 파라미터는 테이블명, 두 번째는 값들의 연관배열입니다.

Note

전달된 모든 값은 자동으로 이스케이프 됩니다.

Updating Data

$this->db->replace()

이 함수는 REPLACE 구문을 실행합니다. 기본적으로 PRIMARYUNIQUE 를 이용하여, DELETE + INSERT 를 사용하는 것입니다. 우리의 경우에, select(), update(), delete(),insert() 를 중복 호출하는 복잡한 로직으로부터 벗어나게 해줄 것입니다.

예제:

$data = array(
        'title' => 'My title',
        'name'  => 'My Name',
        'date'  => 'My date'
);

$this->db->replace('table', $data);

// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

위 예제에서는, title 필드가 기본키라고 가정하면, 그리고 ‘My title’ 이 title의 값이라면, 그 열은 삭제되고 새로운 열로 교체될 것입니다.

set() 함수를 사용하는 것도 가능합니다. 그리고 insert() 와 같이 모든 필드는 이스케이프됩니다.

$this->db->set()

이 함수는 입력(insert) 혹은 업데이트(update)시 값을 설정할 수 있도록 합니다.

이 함수는 입력,업데이트시 데이터 배열을 사용하는 방법 대신 사용할 수 있습니다:

$this->db->set('name', $name);
$this->db->insert('mytable');  // Produces: INSERT INTO mytable (name) VALUES ('{$name}')

함수를 여러 번 호출했을 때는 입력인지 업데이트인지에 따라 적절하게 자동으로 연결해줍니다:

$this->db->set('name', $name);
$this->db->set('title', $title);
$this->db->set('status', $status);
$this->db->insert('mytable');

set() 함수는 옵션으로 세 번째 파라미터($escape)를 받아들입니다. 이 파라미터를 FALSE로 하면 쿼리를 자동으로 이스케이프 하지않습니다. 아래예제는 set() 함수를 호출할 때 세 번째 파라미터를 사용한 것과 안한 것을 비교하여 보여줍니다.

$this->db->set('field', 'field+1', FALSE);
$this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES (field+1)
$this->db->set('field', 'field+1');
$this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES ('field+1')

이 함수를 사용할 때 연관배열을 사용할 수도 있습니다:

$array = array(
        'name' => $name,
        'title' => $title,
        'status' => $status
);

$this->db->set($array);
$this->db->insert('mytable');

객체도 가능합니다:

/*
class Myclass {
        public $title = 'My Title';
        public $content = 'My Content';
        public $date = 'My Date';
}
*/

$object = new Myclass;
$this->db->set($object);
$this->db->insert('mytable');

$this->db->update()

제공된 데이터를 가지고 업데이트 쿼리를 생성하고 실행합니다. 당신은 배열 혹은 객체를 사용하여 데이터를 전달할 수 있습니다. 다음은 배열을 사용한 예입니다:

$data = array(
        'title' => $title,
        'name' => $name,
        'date' => $date
);

$this->db->where('id', $id);
$this->db->update('mytable', $data);
// Produces:
//
//      UPDATE mytable
//      SET title = '{$title}', name = '{$name}', date = '{$date}'
//      WHERE id = $id

아래는 객체를 사용한 예입니다:

/*
class Myclass {
        public $title = 'My Title';
        public $content = 'My Content';
        public $date = 'My Date';
}
*/

$object = new Myclass;
$this->db->where('id', $id);
$this->db->update('mytable', $object);
// Produces: // UPDATE mytable  // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id

Note

전달된 모든 값은 자동으로 이스케이프 됩니다.

$this->db->where() 함수를 이용하면 WHERE 절을 사용할 수 있다는 것을 이미 아실 것입니다. update 함수에서는 옵션으로 where 조건을 세 번째 파라미터로 전달할 수 있습니다:

$this->db->update('mytable', $data, "id = 4");

또는 배열로:

$this->db->update('mytable', $data, array('id' => $id));

업데이트 시 $this->db->set() 함수도 사용할 수 있습니다.

$this->db->update_batch()

제공된 데이터를 가지고 업데이트 쿼리를 생성한 후 실행합니다. 데이터는 배열이나 객체로 제공할 수 있습니다. 배열을 사용한 예:

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name 2' ,
      'date' => 'My date 2'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name 2' ,
      'date' => 'Another date 2'
   )
);

$this->db->update_batch('mytable', $data, 'title');

// Produces:
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title')

첫파라미터는 테이블 명, 둘째 파라미터는 연관배열, 세 번째 파라미터는 where 키입니다.

Note

전달된 모든 값은 자동으로 이스케이프 됩니다.

Note

이 함수가 작동하는 방 식 때문에 affected_rows() 는 이 함수에서 적절한 결과를 주지 않을 것입니다. 대신에 update_batch() 는 실행된 열 수를 반환합니다.

$this->db->get_compiled_update()

이 함수는 INSERT 쿼리 문자열 대신에 UPDATE 쿼리 문자열을 생성한다는 것만 제외하면, $this->db->get_compiled_insert() 과 동일하게 작동합니다.

더 많은 정보를 위해 $this->db->get_compiled_insert() 함수를 참고해주세요.

Note

이 함수는 배치 업데이트에서 작동하지 않습니다.

Deleting Data

$this->db->delete()

삭제 쿼리를 생성하고 실행합니다.

$this->db->delete('mytable', array('id' => $id));  // Produces: // DELETE FROM mytable  // WHERE id = $id

첫 번째 파라미터는 테이블 이름입니다. 두 번째 파라미터는 where 절입니다. 두 번째 파라미터를 사용하는 대신에 where() 나 or_where() 함수를 사용하여 where 절을 설정해도 됩니다:

$this->db->where('id', $id);
$this->db->delete('mytable');

// Produces:
// DELETE FROM mytable
// WHERE id = $id

한 개 이상의 테이블에서 데이터를 삭제해야 한다면 여러 개의 테이블 명을 배열로 delete() 함수에 넘길 수 있습니다.

$tables = array('table1', 'table2', 'table3');
$this->db->where('id', '5');
$this->db->delete($tables);

테이블의 모든 데이터를 삭제하려면 truncate() 혹은 empty_table() 함수를 사용하시면 됩니다.

$this->db->empty_table()

삭제 쿼리를 생성하고 실행합니다:

$this->db->empty_table('mytable'); // Produces: DELETE FROM mytable

$this->db->truncate()

truncate 쿼리를 생성하고 실행합니다.

$this->db->from('mytable');
$this->db->truncate();

// or

$this->db->truncate('mytable');

// Produce:
// TRUNCATE mytable

Note

TRUNCATE 명령이 사용 불가능한 상황이라면 truncate() 함수는 “DELETE FROM table” 쿼리를 실행할 것입니다.

$this->db->get_compiled_delete()

This works exactly the same way as $this->db->get_compiled_insert() except that it produces a DELETE SQL string instead of an INSERT SQL string.

For more information view documentation for $this->db->get_compiled_insert().

함수연결 Method Chaining

함수 연결은 여러 개의 함수를 연결함으로써, 좀 더 단순한 문법을 사용할 수 있게 합니다. 아래 예제를 살펴보세요 :

$query = $this->db->select('title')
                ->where('id', $id)
                ->limit(10, 20)
                ->get('mytable');

쿼리 빌더 캐싱 Query Builder Caching

캐싱이 “true” 가 아닐지라도, 쿼리 빌더는 쿼리의 특정 부분을 나중에 실행할 때에 대비해 저장 (혹은 캐시) 하도록 되어있습니다. 보통은, 액티브레코드 호출이 완료되면, 모든 저장된 데이터는 다음 호출을 위해서 리셋 됩니다. 캐싱을 하면, 이러한 리셋을 막고 데이터 재사용을 쉽게 할 수 있습니다.

캐시된 호출은 누적됩니다. 만약 2개의 캐시된 select() 호출과 2개의 캐시되지않은 select() 호출이 있다면, 4개의 select() 를 호출한 결과가 됩니다. 캐시를 위한 함수는 3개가 있습니다:

$this->db->start_cache()

이 함수는 캐싱을 시작하기 위하여 반드시 호출되어야 합니다. 캐싱이 지원되는 모든 액티브 레코드 쿼리는 나중을 위해서 저장됩니다.

$this->db->stop_cache()

이 함수는 캐싱을 정지하기 위하여 호출합니다.

$this->db->flush_cache()

이 함수는 액티브레코드 캐시로 저장된 모든 아이템을 제거합니다.

캐싱의 사용예제 An example of caching

사용예:

$this->db->start_cache();
$this->db->select('field1');
$this->db->stop_cache();
$this->db->get('tablename');
//Generates: SELECT `field1` FROM (`tablename`)

$this->db->select('field2');
$this->db->get('tablename');
//Generates:  SELECT `field1`, `field2` FROM (`tablename`)

$this->db->flush_cache();
$this->db->select('field2');
$this->db->get('tablename');
//Generates:  SELECT `field2` FROM (`tablename`)

Note

다음의 쿼리문은 캐시될 수 있습니다: select, from, join, where, like, group_by, having, order_by

쿼리 빌더 재설정 Resetting Query Builder

$this->db->reset_query()

Resetting Query Builder allows you to start fresh with your query without executing it first using a method like $this->db->get() or $this->db->insert(). Just like the methods that execute a query, this will not reset items you’ve cached using Query Builder Caching.

This is useful in situations where you are using Query Builder to generate SQL (ex. $this->db->get_compiled_select()) but then choose to, for instance, run the query:

// Note that the second parameter of the get_compiled_select method is FALSE
$sql = $this->db->select(array('field1','field2'))
                                ->where('field3',5)
                                ->get_compiled_select('mytable', FALSE);

// ...
// Do something crazy with the SQL code... like add it to a cron script for
// later execution or something...
// ...

$data = $this->db->get()->result_array();

// Would execute and return an array of results of the following query:
// SELECT field1, field1 from mytable where field3 = 5;

Note

Double calls to get_compiled_select() while you’re using the Query Builder Caching functionality and NOT resetting your queries will results in the cache being merged twice. That in turn will i.e. if you’re caching a select() - select the same field twice.

클래스 레퍼런스

class CI_DB_query_builder
reset_query()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

현재 쿼리 빌더 상태를 재설정합니다. 특정 조건에서 취소가 가능한 쿼리를 생성하고 싶을 때 유용합니다.

start_cache()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

쿼리 빌더 캐시를 시작합니다.

stop_cache()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

쿼리 빌더 캐시를 중지합니다.

flush_cache()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

쿼리 빌더 캐시를 비웁니다.

set_dbprefix([$prefix = ''])
인수:
  • $prefix (string) – The new prefix to use
반환값:

The DB prefix in use

반환형:

문자열

재접속 할 필요없이 데이터베이스 프리픽스를 설정한다.

dbprefix([$table = ''])
인수:
  • $table (string) – The table name to prefix
반환값:

The prefixed table name

반환형:

문자열

환경 설정에 있는 경우 데이터 베이스에 접두사를 추가합니다.

count_all_results([$table = ''[, $reset = TRUE]])
인수:
  • $table (string) – Table name
  • $reset (bool) – Whether to reset values for SELECTs
반환값:

Number of rows in the query result

반환형:

int

쿼리 빌더 에 의해 반환된 모든 레코드의 수를 세는 쿼리 문자열을 생성합니다.

get([$table = ''[, $limit = NULL[, $offset = NULL]]])
인수:
  • $table (string) – The table to query
  • $limit (int) – The LIMIT clause
  • $offset (int) – The OFFSET clause
반환값:

CI_DB_result instance (method chaining)

반환형:

CI_DB_result

쿼리 빌더 함수를 통해 이미 생성된 설렉트 문을 컴파일하고 실행합니다.

get_where([$table = ''[, $where = NULL[, $limit = NULL[, $offset = NULL]]]])
인수:
  • $table (mixed) – The table(s) to fetch data from; string or array
  • $where (string) – The WHERE clause
  • $limit (int) – The LIMIT clause
  • $offset (int) – The OFFSET clause
반환값:

CI_DB_result instance (method chaining)

반환형:

CI_DB_result

get()과 같습니다, 그리고 WHERE 절을 동시에 추가합니다.

select([$select = '*'[, $escape = NULL]])
인수:
  • $select (string) – The SELECT portion of a query
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

SELECT 절을 쿼리에 추가합니다.

select_avg([$select = ''[, $alias = '']])
인수:
  • $select (string) – Field to compute the average of
  • $alias (string) – Alias for the resulting value name
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

SELECT AVG(field) 절을 쿼리에 추가합니다.

select_max([$select = ''[, $alias = '']])
인수:
  • $select (string) – Field to compute the maximum of
  • $alias (string) – Alias for the resulting value name
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

SELECT MAX(field) 절을 쿼리에 추가합니다.

select_min([$select = ''[, $alias = '']])
인수:
  • $select (string) – Field to compute the minimum of
  • $alias (string) – Alias for the resulting value name
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

SELECT MIN(field) 절을 쿼리에 추가합니다.

select_sum([$select = ''[, $alias = '']])
인수:
  • $select (string) – Field to compute the sum of
  • $alias (string) – Alias for the resulting value name
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

SELECT SUM(field) 절을 쿼리에 추가합니다.

distinct([$val = TRUE])
인수:
  • $val (bool) – Desired value of the “distinct” flag
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리의 SELECT 부분에 DISTINCT 절을 추가하는 쿼리 빌더를 알려주는 플래그를 설정합니다

from($from)
인수:
  • $from (mixed) – Table name(s); string or array
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리의 FROM 절을 지정합니다.

join($table, $cond[, $type = ''[, $escape = NULL]])
인수:
  • $table (string) – Table name to join
  • $cond (string) – The JOIN ON condition
  • $type (string) – The JOIN type
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 JOIN 문을 생성합니다.

where($key[, $value = NULL[, $escape = NULL]])
인수:
  • $key (mixed) – Name of field to compare, or associative array
  • $value (mixed) – If a single key, compared to this value
  • $escape (boolean) – Whether to escape values and identifiers
반환값:

DB_query_builder instance

반환형:

object

쿼리의 WHERE 절에. ‘AND’ 로 연결하여 생성합니다.

or_where($key[, $value = NULL[, $escape = NULL]])
인수:
  • $key (mixed) – Name of field to compare, or associative array
  • $value (mixed) – If a single key, compared to this value
  • $escape (boolean) – Whether to escape values and identifiers
반환값:

DB_query_builder instance

반환형:

object

쿼리의 WHERE 절에 . ‘OR’ 로 구분하여 생성합니다.

or_where_in([$key = NULL[, $values = NULL[, $escape = NULL]]])
인수:
  • $key (string) – The field to search
  • $values (array) – The values searched on
  • $escape (boolean) – Whether to escape identifiers
반환값:

DB_query_builder instance

반환형:

object

WHERE field IN(‘item’, ‘item’) 부분을 생성하며 필요한 경우 OR 로 연결해줍니다.

or_where_not_in([$key = NULL[, $values = NULL[, $escape = NULL]]])
인수:
  • $key (string) – The field to search
  • $values (array) – The values searched on
  • $escape (boolean) – Whether to escape identifiers
반환값:

DB_query_builder instance

반환형:

object

WHERE field NOT IN(‘item’, ‘item’) 부분을 생성하며 필요한 경우 OR 로 연결해줍니다.

where_in([$key = NULL[, $values = NULL[, $escape = NULL]]])
인수:
  • $key (string) – Name of field to examine
  • $values (array) – Array of target values
  • $escape (boolean) – Whether to escape identifiers
반환값:

DB_query_builder instance

반환형:

object

WHERE field IN(‘item’, ‘item’) 부분을 생성하며 필요한 경우 AND 로 연결해줍니다.

where_not_in([$key = NULL[, $values = NULL[, $escape = NULL]]])
인수:
  • $key (string) – Name of field to examine
  • $values (array) – Array of target values
  • $escape (boolean) – Whether to escape identifiers
반환값:

DB_query_builder instance

반환형:

object

WHERE field NOT IN(‘item’, ‘item’) 부분을 생성하며 필요한 경우 AND 로 연결해줍니다.

group_start()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

괄호 묶음 시작, 괄호 안에 AND 을 사용합니다.

or_group_start()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

괄호 묶음 시작, 괄호 안에 OR 를 사용합니다.

not_group_start()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

괄호 묶음 시작, 괄호 안에 AND NOT 을 사용합니다.

or_not_group_start()
반환값:CI_DB_query_builder instance (method chaining)
반환형:CI_DB_query_builder

괄호 묶음 시작, 괄호 안에 OR NOT 을 사용합니다.

group_end()
반환값:DB_query_builder instance
반환형:object

괄호 묶음 종료

like($field[, $match = ''[, $side = 'both'[, $escape = NULL]]])
인수:
  • $field (string) – Field name
  • $match (string) – Text portion to match
  • $side (string) – Which side of the expression to put the ‘%’ wildcard on
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 AND 구문을 통해 여러 LIKE 절을 추가합니다.

or_like($field[, $match = ''[, $side = 'both'[, $escape = NULL]]])
인수:
  • $field (string) – Field name
  • $match (string) – Text portion to match
  • $side (string) – Which side of the expression to put the ‘%’ wildcard on
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 OR 구문을 통해 여러 LIKE 절을 추가합니다.

not_like($field[, $match = ''[, $side = 'both'[, $escape = NULL]]])
인수:
  • $field (string) – Field name
  • $match (string) – Text portion to match
  • $side (string) – Which side of the expression to put the ‘%’ wildcard on
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 AND 구문을 통해 여러 NOT LIKE 절을 추가합니다.

or_not_like($field[, $match = ''[, $side = 'both'[, $escape = NULL]]])
인수:
  • $field (string) – Field name
  • $match (string) – Text portion to match
  • $side (string) – Which side of the expression to put the ‘%’ wildcard on
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 OR 구문을 통해 여러 NOT LIKE 절을 추가합니다.

having($key[, $value = NULL[, $escape = NULL]])
인수:
  • $key (mixed) – Identifier (string) or associative array of field/value pairs
  • $value (string) – Value sought if $key is an identifier
  • $escape (string) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 AND 구문을 통해 여러 HAVING 절을 추가합니다.

or_having($key[, $value = NULL[, $escape = NULL]])
인수:
  • $key (mixed) – Identifier (string) or associative array of field/value pairs
  • $value (string) – Value sought if $key is an identifier
  • $escape (string) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 OR 구문을 통해 여러 HAVING 절을 추가합니다.

group_by($by[, $escape = NULL])
인수:
  • $by (mixed) – Field(s) to group by; string or array
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 GROUP BY 절을 추가합니다.

order_by($orderby[, $direction = ''[, $escape = NULL]])
인수:
  • $orderby (string) – Field to order by
  • $direction (string) – The order requested - ASC, DESC or random
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 ORDER BY 절을 추가합니다.

limit($value[, $offset = 0])
인수:
  • $value (int) – Number of rows to limit the results to
  • $offset (int) – Number of rows to skip
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 LIMIT와 OFFSET 절을 추가합니다.

offset($offset)
인수:
  • $offset (int) – Number of rows to skip
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

쿼리에 OFFSET 절을 추가합니다.

set($key[, $value = ''[, $escape = NULL]])
인수:
  • $key (mixed) – Field name, or an array of field/value pairs
  • $value (string) – Field value, if $key is a single field
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

insert(), update() or replace() 를 통해 테이블에 입력될 필드/값 추가.

insert([$table = ''[, $set = NULL[, $escape = NULL]]])
인수:
  • $table (string) – Table name
  • $set (array) – An associative array of field/value pairs
  • $escape (bool) – Whether to escape values and identifiers
반환값:

TRUE on success, FALSE on failure

반환형:

bool

INSERT 쿼리를 컴파일하고 실행합니다.

insert_batch($table[, $set = NULL[, $escape = NULL[, $batch_size = 100]]])
인수:
  • $table (string) – Table name
  • $set (array) – Data to insert
  • $escape (bool) – Whether to escape values and identifiers
  • $batch_size (int) – Count of rows to insert at once
반환값:

Number of rows inserted or FALSE on failure

반환형:

mixed

INSERT 쿼리를 컴파일하고 실행합니다.

Note

$batch_size 열보다 더 많이 제공되면, 다중 INSERT 쿼리가 실행됩니다. 각각은 최대 $batch_size 만큼을 실행합니다.

set_insert_batch($key[, $value = ''[, $escape = NULL]])
인수:
  • $key (mixed) – Field name or an array of field/value pairs
  • $value (string) – Field value, if $key is a single field
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

insert_batch() 를 통해 테이블에 입력될 필드/값 추가.

update([$table = ''[, $set = NULL[, $where = NULL[, $limit = NULL]]]])
인수:
  • $table (string) – Table name
  • $set (array) – An associative array of field/value pairs
  • $where (string) – The WHERE clause
  • $limit (int) – The LIMIT clause
반환값:

TRUE on success, FALSE on failure

반환형:

bool

UPDATE 쿼리를 컴파일하고 실행합니다.

update_batch($table[, $set = NULL[, $value = NULL[, $batch_size = 100]]])
인수:
  • $table (string) – Table name
  • $set (array) – Field name, or an associative array of field/value pairs
  • $value (string) – Field value, if $set is a single field
  • $batch_size (int) – Count of conditions to group in a single query
반환값:

Number of rows updated or FALSE on failure

반환형:

mixed

UPDATE 쿼리를 컴파일하고 실행합니다.

Note

$batch_size 열보다 더 많이 제공되면, 다중 INSERT 쿼리가 실행됩니다. 각각은 최대 $batch_size 만큼을 실행합니다.

set_update_batch($key[, $value = ''[, $escape = NULL]])
인수:
  • $key (mixed) – Field name or an array of field/value pairs
  • $value (string) – Field value, if $key is a single field
  • $escape (bool) – Whether to escape values and identifiers
반환값:

CI_DB_query_builder instance (method chaining)

반환형:

CI_DB_query_builder

update_batch() 를 통해 테이블에 업데이트될 필드/값 추가.

replace([$table = ''[, $set = NULL]])
인수:
  • $table (string) – Table name
  • $set (array) – An associative array of field/value pairs
반환값:

TRUE on success, FALSE on failure

반환형:

bool

REPLACE 쿼리를 컴파일하고 실행합니다.

delete([$table = ''[, $where = ''[, $limit = NULL[, $reset_data = TRUE]]]])
인수:
  • $table (mixed) – The table(s) to delete from; string or array
  • $where (string) – The WHERE clause
  • $limit (int) – The LIMIT clause
  • $reset_data (bool) – TRUE to reset the query “write” clause
반환값:

CI_DB_query_builder instance (method chaining) or FALSE on failure

반환형:

mixed

DELETE 쿼리를 컴파일하고 실행합니다.

truncate([$table = ''])
인수:
  • $table (string) – Table name
반환값:

TRUE on success, FALSE on failure

반환형:

bool

테이블에 TRUNCATE 문을 실행합니다.

Note

데이터베이스 플랫폼이 TRUNCATE을 지원하지 않으면, DELETE 문이 대신 사용됩니다.

empty_table([$table = ''])
인수:
  • $table (string) – Table name
반환값:

TRUE on success, FALSE on failure

반환형:

bool

DELETE 문을 통해 테이블에서 모든 기록을 삭제합니다.

get_compiled_select([$table = ''[, $reset = TRUE]])
인수:
  • $table (string) – Table name
  • $reset (bool) – Whether to reset the current QB values or not
반환값:

The compiled SQL statement as a string

반환형:

문자열

SELECT 문을 컴파일하고 문자열로 반환합니다.

get_compiled_insert([$table = ''[, $reset = TRUE]])
인수:
  • $table (string) – Table name
  • $reset (bool) – Whether to reset the current QB values or not
반환값:

The compiled SQL statement as a string

반환형:

문자열

INSERT 문을 컴파일하고 문자열로 반환합니다.

get_compiled_update([$table = ''[, $reset = TRUE]])
인수:
  • $table (string) – Table name
  • $reset (bool) – Whether to reset the current QB values or not
반환값:

The compiled SQL statement as a string

반환형:

문자열

UPDATE 문을 컴파일하고 문자열로 반환합니다.

get_compiled_delete([$table = ''[, $reset = TRUE]])
인수:
  • $table (string) – Table name
  • $reset (bool) – Whether to reset the current QB values or not
반환값:

The compiled SQL statement as a string

반환형:

문자열

DELETE 문을 컴파일하고 문자열로 반환합니다.