쿼리 빌더 클래스

CodeIgniter를 사용하면 쿼리 빌더 클래스에 액세스 할 수 있습니다. 이 패턴을 사용하면 최소한의 스크립팅으로 데이터베이스에서 정보를 검색, 삽입 및 업데이트를 할 수 있습니다. 경우에 따라 데이터베이스 작업을 수행하는데 한두 줄의 코드만 사용해도 됩니다. CodeIgniter에서는 데이터베이스의 각 테이블이 클래스 파일일 필요는 없습니다. 대신 더 간단한 인터페이스를 제공합니다.

단순성을 넘어서, Query Builder 기능을 사용하면 각 데이터베이스 어댑터별 조회 구문이 생성되는 이점이 있어 특정 데이터베이스에 종속되지 않는 어플리케이션을 작성할 수 있다는 것입니다. 또한 값이 시스템에 의해 자동으로 이스케이프되므로 보다 안전한 쿼리가 가능합니다.

Note

CodeIgniter는 데이터베이스, 테이블, 열(column) 이름에서 점(.)을 지원하지 않습니다.

SQL Injection 보호

쿼리 빌더를 사용하여 SQL 문을 매우 안전하게 생성할 수 있습니다. 그러나 전달되는 모든 데이터에 대해 SQL 주입을 방지하도록 설계되지는 않았습니다.

쿼리 빌더에 전달되는 인수는 다음과 같습니다.

  1. 필드(또는 테이블) 이름과 같은 식별자(identifiers)

  2. 값(values)

  3. SQL 문자열의 일부

쿼리 빌더는 기본적으로 모든 값(values)을 이스케이프합니다.

또한 기본적으로 SQL 문자열에 포함된 식별자(identifiers)식별자(identifiers)를 적절하게 보호하려고 시도합니다. 이는 많은 사용 사례에서 잘 작동하도록 구현되어 있지만, 모든 공격을 차단하도록 설계된 것은 아닙니다. 따라서 적절한 유효성 검사 없이 사용자 입력을 입력해서는 안 됩니다.

또한 많은 메소드에는 이스케이프를 비활성화하도록 설정할 수 있는 $escape 매개변수가 있습니다. $escape가 false로 설정되면 쿼리 빌더에서 보호를 제공하지 않으므로 쿼리 빌더에 전달하기 전에 사용자가 직접 제대로 이스케이프되거나 보호되는지 확인해야 합니다. 원시 SQL 문을 지정하는 RawSql을 사용할 때도 마찬가지입니다.

쿼리 빌더 로드

쿼리 빌더는 데이터베이스 연결의 table() 메소드를 통해 로드됩니다. 그러면 쿼리의 FROM 부분이 설정되고 Query Builder 클래스의 새 인스턴스가 반환됩니다.

<?php

$db      = \Config\Database::connect();
$builder = $db->table('users');

Query Builder는 특별히 클래스를 요청할 때만 메모리에 로드되므로 기본적으로 자원(resource)이 사용되지 않습니다.

데이터 선택(select)

다음 함수를 사용하면 SQL SELECT 문을 작성할 수 있습니다.

Get

$builder->get()

select 쿼리를 실행하고 결과를 반환하며, 테이블에서 모든 레코드를 검색할 수 있습니다

<?php

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

첫 번째와 두 번째 매개 변수를 사용하여 limit과 offset을 설정할 수 있습니다

<?php

$query = $builder->get(10, 20);
/*
 * Executes: SELECT * FROM mytable LIMIT 20, 10
 * (in MySQL. Other databases have slightly different syntax)
 */

위 함수는 $query 라는 변수에 할당되어 있으며 결과를 표시하는데 사용할 수 있습니다.

<?php

$query = $builder->get();

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

결과 생성에 대한 자세한 내용은 getResult*() 함수 페이지를 참조하십시오.

$builder->getCompiledSelect()

$builder->get()처럼 select 쿼리를 컴파일하지만 쿼리를 실행하지는 않습니다. 이 메소드는 SQL 쿼리를 문자열로 반환합니다.

<?php

$sql = $builder->getCompiledSelect();
echo $sql;
// Prints string: SELECT * FROM mytable

첫 번째 매개 변수를 사용하면 쿼리 빌더의 쿼리를 재설정할지 여부를 설정할 수 있습니다. (기본적으로 $builder->get()을 사용할 때와 같이 재설정됩니다)

<?php

echo $builder->limit(10, 20)->getCompiledSelect(false);
/*
 * Prints string: SELECT * FROM mytable LIMIT 20, 10
 * (in MySQL. Other databases have slightly different syntax)
 */

echo $builder->select('title, content, date')->getCompiledSelect();
// Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10

위의 예에서 주목해야 할 핵심은 두 번째 쿼리는 limit(10, 20)을 사용하지 않았지만 생성된 SQL 쿼리에는 LIMIT 20, 10이 있다는 것입니다. 그 이유는 첫 번째 매개변수가 false로 설정되어 있기 때문입니다.

$builder->getWhere()

db->where() 함수를 사용하는 대신 첫 번째 매개 변수에 “where”절을 추가 할 수 있다는 점을 제외하고 get() 메소드와 동일합니다.

<?php

$query = $builder->getWhere(['id' => $id], $limit, $offset);

자세한 내용은 아래의 where 함수에 대해 읽으십시오.

Select

$builder->select()

쿼리의 SELECT 부분을 쓸 수 있습니다

<?php

$builder->select('title, content, date');
$query = $builder->get();
// Executes: SELECT title, content, date FROM mytable

Note

테이블에서 모두(*)를 선택하는 경우 이 방법을 사용할 필요가 없습니다. 생략하면 CodeIgniter는 모든 필드를 선택하고 자동으로 SELECT *를 추가한다고 가정합니다.

$builder->select()는 두 번째 매개 변수를 옵션으로 허용하며, 이를 false로 설정하면 CodeIgniter는 필드 또는 테이블 이름을 보호하지 않습니다. 필드의 자동 이스케이프가 필드를 손상시킬 수 있는 복합 선택문이 필요한 경우에 유용합니다.

<?php

$builder->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4) AS amount_paid', false);
$query = $builder->get();
RawSql

v4.2.0부터 $builder->select()는 원시(raw) SQL 문자열을 표현하는 CodeIgniter\Database\RawSql 인스턴스를 허용합니다.

<?php

use CodeIgniter\Database\RawSql;

$sql = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral';
$builder->select(new RawSql($sql));
$query = $builder->get();

Warning

RawSql을 사용할 때 값과 식별자(identifier)는 수동으로 이스케이프(escape)해야 합니다. 그렇지 않으면 SQL 주입(SQL injection)이 발생할 수 있습니다.

$builder->selectMax()

쿼리의 SELECT MAX(field) 부분을 작성합니다. 옵션으로 두 번째 매개 변수에 결과 필드의 이름을 전달하여 바꿀 수 있습니다.

<?php

$builder->selectMax('age');
$query = $builder->get();
// Produces: SELECT MAX(age) as age FROM mytable

$builder->selectMax('age', 'member_age');
$query = $builder->get();
// Produces: SELECT MAX(age) as member_age FROM mytable

$builder->selectMin()

쿼리의 SELECT MIN(field) 부분을 작성합니다. selectMax()와 마찬가지로 결과 필드의 이름을 바꾸는 두 번째 매개 변수를 옵션으로 제공합니다.

<?php

$builder->selectMin('age');
$query = $builder->get();
// Produces: SELECT MIN(age) as age FROM mytable

$builder->selectAvg()

쿼리의 SELECT AVG(field) 부분을 작성합니다. selectMax()와 마찬가지로 결과 필드의 이름을 바꾸는 두 번째 매개 변수를 옵션으로 제공합니다.

<?php

$builder->selectAvg('age');
$query = $builder->get();
// Produces: SELECT AVG(age) as age FROM mytable

$builder->selectSum()

쿼리의 SELECT SUM(field) 부분을 작성합니다. selectMax()와 마찬가지로 결과 필드의 이름을 바꾸는 두 번째 매개 변수를 옵션으로 제공합니다.

<?php

$builder->selectSum('age');
$query = $builder->get();
// Produces: SELECT SUM(age) as age FROM mytable

$builder->selectCount()

쿼리의 SELECT COUNT(field) 부분을 작성합니다. selectMax()와 마찬가지로 결과 필드의 이름을 바꾸는 두 번째 매개 변수를 옵션으로 제공합니다.

Note

이 메소드는 groupBy()와 함께 사용할 때 특히 유용합니다. 카운트 결과는 일반적으로 countAll() 또는 countAllResults()를 참조하십시오.

<?php

$builder->selectCount('age');
$query = $builder->get();
// Produces: SELECT COUNT(age) as age FROM mytable

$builder->selectSubquery()

SELECT 섹션에 서브쿼리(subquery)를 추가합니다.

$subquery = $db->table('countries')->select('name')->where('id', 1);
$builder  = $db->table('users')->select('name')->selectSubquery($subquery, 'country');
$query    = $builder->get();
// Produces: SELECT `name`, (SELECT `name` FROM `countries` WHERE `id` = 1) `country` FROM `users`

From

$builder->from()

쿼리의 FROM 부분을 작성합니다.

<?php

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

Note

앞에서 설명한 것처럼 쿼리의 FROM 부분은 $db->table() 메소드에서 지정할 수 있습니다. from()에 대한 추가 호출은 쿼리의 FROM 부분에 더 많은 테이블을 추가합니다.

Subqueries

$builder->fromSubquery()

Permits you to write part of a FROM query as a subquery.

This is where we add a subquery to an existing table: FROM 쿼리의 일부를 서브쿼리(subquery)로 작성할 수 있습니다.

기존 테이블에 서브쿼리를 추가합니다.

<?php

$subquery = $db->table('users');
$builder  = $db->table('jobs')->fromSubquery($subquery, 'alias');
$query    = $builder->get();
// Produces: SELECT * FROM `jobs`, (SELECT * FROM `users`) `alias`

$db->newQuery() 메서드를 사용하면 서브쿼리를 기본 테이블로 만듭니다.

<?php

$subquery = $db->table('users')->select('id, name');
$builder  = $db->newQuery()->fromSubquery($subquery, 't');
$query    = $builder->get();
// Produces: SELECT * FROM (SELECT `id`, `name` FROM users) `t`

Join

$builder->join()

쿼리의 JOIN 부분을 작성합니다.

<?php

$builder = $db->table('blogs');
$builder->select('*');
$builder->join('comments', 'comments.id = blogs.id');
$query = $builder->get();
/*
 * Produces:
 * SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
 */

하나의 쿼리에 여러 개의 조인이 필요한 경우 메소드를 여러번 호출할 수 있습니다.

특정 유형의 JOIN이 필요한 경우 함수의 세 번째 매개 변수를 통해 지정할 수 있습니다. 제공 옵션 : left, right, outer, inner, left outer, right outer.

<?php

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

v4.2.0부터 $builder->join()는 원시(raw) SQL 문자열을 표현하는 CodeIgniter\Database\RawSql 인스턴스를 허용합니다.

<?php

use CodeIgniter\Database\RawSql;

$sql = 'user.id = device.user_id AND ((1=1 OR 1=1) OR (1=1 OR 1=1))';
$builder->join('user', new RawSql($sql), 'LEFT');
// Produces: LEFT JOIN "user" ON user.id = device.user_id AND ((1=1 OR 1=1) OR (1=1 OR 1=1))

Warning

RawSql을 사용할 때 값과 식별자(identifier)는 수동으로 이스케이프(escape)해야 합니다. 그렇지 않으면 SQL 주입(SQL injection)이 발생할 수 있습니다.

특정 데이터 찾기

Where

$builder->where()

이 메소드를 사용하면 네 가지 방법중 하나를 사용하여 WHERE 절을 설정할 수 있습니다:

Note

이 메소드에 전달된 모든 값(사용자 지정 문자열은 제외됨)은 자동으로 이스케이프되어 안전한 쿼리를 생성합니다.

Note

$builder->where()는 세 번째 매개 변수를 옵션으로 허용하며, false로 설정하면 CodeIgniter는 필드 또는 테이블 이름을 보호하지 않습니다.

1. key/value 메소드
<?php

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

등호(=)가 추가되었습니다.

여러 함수 호출을 사용하는 경우 AND와 함께 체인으로 연결됩니다:

<?php

$builder->where('name', $name);
$builder->where('title', $title);
$builder->where('status', $status);
// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
2. 사용자정의 key/value 메소드

비교를 제어하기 위해 첫 번째 매개 변수에 연산자를 포함시킬 수 있습니다:

<?php

$builder->where('name !=', $name);
$builder->where('id <', $id);
// Produces: WHERE name != 'Joe' AND id < 45
3. 연관 배열 메소드
<?php

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

이 메소드를 사용하여 사용자 연산자를 포함시킬 수도 있습니다:RawSql

<?php

$array = ['name !=' => $name, 'id <' => $id, 'date >' => $date];
$builder->where($array);
4. 맞춤 문자열

비교절을 직접 작성할 수 있습니다

<?php

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

Warning

문자열 내에 사용자 지정 데이터를 사용하는 경우 값과 식별자(identifier)를 수동으로 이스케이프해야 합니다. 그렇지 않으면 SQL 주입(SQL injection)이 발생할 수 있습니다.

<?php

$name  = $builder->db->escape('Joe');
$where = "name={$name} AND status='boss' OR status='active'";
$builder->where($where);
5. RawSql

v4.2.0부터 $builder->where()는 원시(raw) SQL 문자열을 표현하는 CodeIgniter\Database\RawSql 인스턴스를 허용합니다.

<?php

use CodeIgniter\Database\RawSql;

$sql = "id > 2 AND name != 'Accountant'";
$builder->where(new RawSql($sql));

Warning

RawSql을 사용할 때 값과 식별자(identifier)는 수동으로 이스케이프(escape)해야 합니다. 그렇지 않으면 SQL 주입(SQL injection)이 발생할 수 있습니다.

6. Subqueries
<?php

// With closure
$builder->where('advance_amount <', static fn (BaseBuilder $builder) => $builder->select('MAX(advance_amount)', false)->from('orders')->where('id >', 2));
// Produces: WHERE "advance_amount" < (SELECT MAX(advance_amount) FROM "orders" WHERE "id" > 2)

// With builder directly
$subQuery = $db->table('orders')->select('MAX(advance_amount)', false)->where('id >', 2);
$builder->where('advance_amount <', $subQuery);

$builder->orWhere()

이 함수는 여러 인스턴스가 OR로 결합된다는 점을 제외하고 위의 메소드와 동일합니다.

<?php

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

$builder->whereIn()

AND로 결합된 WHERE field IN ('item', 'item') SQL 쿼리를 생성합니다.

<?php

$names = ['Frank', 'Todd', 'James'];
$builder->whereIn('username', $names);
// Produces: WHERE username IN ('Frank', 'Todd', 'James')

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->whereIn('id', static fn (BaseBuilder $builder) => $builder->select('job_id')->from('users_jobs')->where('user_id', 3));
// Produces: WHERE "id" IN (SELECT "job_id" FROM "users_jobs" WHERE "user_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('job_id')->where('user_id', 3);
$builder->whereIn('id', $subQuery);

$builder->orWhereIn()

OR로 결합된 WHERE field IN ('item', 'item') SQL 쿼리를 생성합니다.

<?php

$names = ['Frank', 'Todd', 'James'];
$builder->orWhereIn('username', $names);
// Produces: OR username IN ('Frank', 'Todd', 'James')

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->orWhereIn('id', static fn (BaseBuilder $builder) => $builder->select('job_id')->from('users_jobs')->where('user_id', 3));
// Produces: OR "id" IN (SELECT "job_id" FROM "users_jobs" WHERE "user_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('job_id')->where('user_id', 3);
$builder->orWhereIn('id', $subQuery);

$builder->whereNotIn()

AND로 결합된 WHERE field NOT IN ('item', 'item') SQL 쿼리를 생성합니다.

<?php

$names = ['Frank', 'Todd', 'James'];
$builder->whereNotIn('username', $names);
// Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->whereNotIn('id', static fn (BaseBuilder $builder) => $builder->select('job_id')->from('users_jobs')->where('user_id', 3));
// Produces: WHERE "id" NOT IN (SELECT "job_id" FROM "users_jobs" WHERE "user_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('job_id')->where('user_id', 3);
$builder->whereNotIn('id', $subQuery);

$builder->orWhereNotIn()

OR로 결합된 WHERE field NOT IN ('item', 'item') SQL 쿼리를 생성합니다.

<?php

$names = ['Frank', 'Todd', 'James'];
$builder->orWhereNotIn('username', $names);
// Produces: OR username NOT IN ('Frank', 'Todd', 'James')

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->orWhereNotIn('id', static fn (BaseBuilder $builder) => $builder->select('job_id')->from('users_jobs')->where('user_id', 3));
// Produces: OR "id" NOT IN (SELECT "job_id" FROM "users_jobs" WHERE "user_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('job_id')->where('user_id', 3);
$builder->orWhereNotIn('id', $subQuery);

유사한 데이터 찾기

Like

$builder->like()

이 메소드를 사용하면 검색에 유용한 LIKE절을 생성할 수 있습니다.

Note

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

Note

모든 like*() 메소드의 변형은 메소드의 다섯 번째 매개 변수에 true를 전달하여 대소문자를 구분하지 않는 검색을 수행하도록 강제할 수 있습니다. 그렇지 않으면 가능한 경우 플랫폼별 기능을 사용하여 값을 소문자로 만듭니다. (예 :HAVING LOWER (column) LIKE '% search %'). 이를 위해서는 column 대신 LOWER(column)에 대해 인덱스를 작성해야 할 수 있습니다.

1. key/value 메소드
<?php

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

메소드 호출을 여러번 하게되면 AND와 함께 체인으로 연결됩니다.

<?php

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

와일드카드(%)의 위치를 제어하려면 옵션으로 지정된 세 번째 인수를 사용합니다. 옵션 : before, after, both(기본값)

<?php

$builder->like('title', 'match', 'before'); // Produces: WHERE `title` LIKE '%match' ESCAPE '!'
$builder->like('title', 'match', 'after');  // Produces: WHERE `title` LIKE 'match%' ESCAPE '!'
$builder->like('title', 'match', 'both');   // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
2. 연관 배열 메소드
<?php

$array = ['title' => $match, 'page1' => $match, 'page2' => $match];
$builder->like($array);
// WHERE `title` LIKE '%match%' ESCAPE '!' AND  `page1` LIKE '%match%' ESCAPE '!' AND  `page2` LIKE '%match%' ESCAPE '!'
3. RawSql

v4.2.0부터 $builder->like()는 원시(raw) SQL 문자열을 표현하는 CodeIgniter\Database\RawSql 인스턴스를 허용합니다.

<?php

use CodeIgniter\Database\RawSql;

$sql    = "CONCAT(users.name, ' ', IF(users.surname IS NULL OR users.surname = '', '', users.surname))";
$rawSql = new RawSql($sql);
$builder->like($rawSql, 'value', 'both');

Warning

RawSql을 사용할 때 값과 식별자(identifier)는 수동으로 이스케이프(escape)해야 합니다. 그렇지 않으면 SQL 주입(SQL injection)이 발생할 수 있습니다.

$builder->orLike()

이 메소드는 여러 인스턴스가 OR로 결합된다는 점을 제외하면 위의 메소드와 동일합니다.

<?php

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

$builder->notLike()

이 메소드는 NOT LIKE문을 생성한다는 점을 제외하면 like()와 동일합니다.

<?php

$builder->notLike('title', 'match'); // WHERE `title` NOT LIKE '%match% ESCAPE '!'

$builder->orNotLike()

이 메소드는 여러 인스턴스가 OR로 결합된다는 점을 제외하면 notLike()와 동일합니다.

<?php

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

$builder->groupBy()

검색어의 GROUP BY 부분을 작성합니다.

<?php

$builder->groupBy('title');
// Produces: GROUP BY title

여러 값의 배열을 전달할 수도 있습니다.

<?php

$builder->groupBy(['title', 'date']);
// Produces: GROUP BY title, date

$builder->distinct()

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

<?php

$builder->distinct();
$builder->get();
// Produces: SELECT DISTINCT * FROM mytable

$builder->having()

쿼리의 HAVING 부분을 작성합니다. 가능한 구문은 2개이며, 인수는 1개 또는 2개입니다.

<?php

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

여러 값의 배열을 전달할 수도 있습니다.

<?php

$builder->having(['title =' => 'My Title', 'id <' => $id]);
// Produces: HAVING title = 'My Title', id < 45

CodeIgniter는 기본적으로 값(value)을 이스케이프하여 데이터베이스에 전송합니다. 이스케이프되는 것을 방지하고 싶다면 옵션으로 지정된 세 번째 인수를 false로 설정하십시오.

<?php

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

$builder->orHaving()

having()과 동일하며 여러 절을 OR로 구분합니다.

$builder->havingIn()

AND로 결합된 HAVING field IN ( 'item', 'item') SQL쿼리를 생성합니다.

<?php

$groups = [1, 2, 3];
$builder->havingIn('group_id', $groups);
// Produces: HAVING group_id IN (1, 2, 3)

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->havingIn('id', static fn (BaseBuilder $builder) => $builder->select('user_id')->from('users_jobs')->where('group_id', 3));
// Produces: HAVING "id" IN (SELECT "user_id" FROM "users_jobs" WHERE "group_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('user_id')->where('group_id', 3);
$builder->havingIn('id', $subQuery);

$builder->orHavingIn()

OR로 결합된 HAVING field IN ( 'item', 'item') SQL 쿼리를 생성합니다.

<?php

$groups = [1, 2, 3];
$builder->orHavingIn('group_id', $groups);
// Produces: OR group_id IN (1, 2, 3)

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->orHavingIn('id', static fn (BaseBuilder $builder) => $builder->select('user_id')->from('users_jobs')->where('group_id', 3));
// Produces: OR "id" IN (SELECT "user_id" FROM "users_jobs" WHERE "group_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('user_id')->where('group_id', 3);
$builder->orHavingIn('id', $subQuery);

$builder->havingNotIn()

AND로 결합된 HAVING field NOT IN ( 'item', 'item') SQL 쿼리를 생성합니다.

<?php

$groups = [1, 2, 3];
$builder->havingNotIn('group_id', $groups);
// Produces: HAVING group_id NOT IN (1, 2, 3)

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->havingNotIn('id', static fn (BaseBuilder $builder) => $builder->select('user_id')->from('users_jobs')->where('group_id', 3));
// Produces: HAVING "id" NOT IN (SELECT "user_id" FROM "users_jobs" WHERE "group_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('user_id')->where('group_id', 3);
$builder->havingNotIn('id', $subQuery);

$builder->orHavingNotIn()

OR로 결합된 HAVING field NOT IN ( 'item', 'item') SQL 쿼리를 생성합니다.

<?php

$groups = [1, 2, 3];
$builder->havingNotIn('group_id', $groups);
// Produces: OR group_id NOT IN (1, 2, 3)

값 배열 대신 서브 쿼리를 사용할 수 있습니다.

<?php

// With closure
$builder->orHavingNotIn('id', static fn (BaseBuilder $builder) => $builder->select('user_id')->from('users_jobs')->where('group_id', 3));
// Produces: OR "id" NOT IN (SELECT "user_id" FROM "users_jobs" WHERE "group_id" = 3)

// With builder directly
$subQuery = $db->table('users_jobs')->select('user_id')->where('group_id', 3);
$builder->orHavingNotIn('id', $subQuery);

$builder->havingLike()

이 메소드를 사용하면 HAVING 부분 대해 LIKE 절을 생성할 수 있으며 검색에 유용합니다.

Note

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

Note

모든 havingLike*() 메소드의 변형은 메소드의 다섯 번째 매개 변수에 true를 전달하여 대소문자를 구분하지 않는 검색을 수행하도록 강제할 수 있습니다. 그렇지 않으면 가능한 경우 플랫폼별 기능을 사용하여 값을 소문자로 만듭니다. (예 :HAVING LOWER (column) LIKE '% search %'). 이를 위해서는 column 대신 LOWER(column)에 대해 인덱스를 작성해야 할 수 있습니다.

1. key/value 메소드
<?php

$builder->havingLike('title', 'match');
// Produces: HAVING `title` LIKE '%match%' ESCAPE '!'

메소드를 여러번 호출하는 경우 AND와 함께 체인으로 연결됩니다.

<?php

$builder->havingLike('title', 'match');
$builder->havingLike('body', 'match');
// HAVING `title` LIKE '%match%' ESCAPE '!' AND  `body` LIKE '%match% ESCAPE '!'

와일드카드(%)의 위치를 제어하려면 옵션으로 지정된 세 번째 인수를 사용합니다. 옵션 : before, after, both(기본값)

<?php

$builder->havingLike('title', 'match', 'before'); // Produces: HAVING `title` LIKE '%match' ESCAPE '!'
$builder->havingLike('title', 'match', 'after');  // Produces: HAVING `title` LIKE 'match%' ESCAPE '!'
$builder->havingLike('title', 'match', 'both');   // Produces: HAVING `title` LIKE '%match%' ESCAPE '!'
2. 연관 배열 메소드
<?php

$array = ['title' => $match, 'page1' => $match, 'page2' => $match];
$builder->havingLike($array);
// HAVING `title` LIKE '%match%' ESCAPE '!' AND  `page1` LIKE '%match%' ESCAPE '!' AND  `page2` LIKE '%match%' ESCAPE '!'

$builder->orHavingLike()

이 메소드는 여러 인스턴스가 OR로 결합된다는 점을 제외하면 위의 메소드와 동일합니다.

<?php

$builder->havingLike('title', 'match');
$builder->orHavingLike('body', $match);
// HAVING `title` LIKE '%match%' ESCAPE '!' OR  `body` LIKE '%match%' ESCAPE '!'

$builder->notHavingLike()

이 메소드는 NOT LIKE문을 생성한다는 점을 제외하면 havingLike()와 동일합니다.

<?php

$builder->notHavingLike('title', 'match');
// HAVING `title` NOT LIKE '%match% ESCAPE '!'

$builder->orNotHavingLike()

이 메소드는 여러 인스턴스가 OR로 결합된다는 점을 제외하면 notHavingLike()와 동일합니다.

<?php

$builder->havingLike('title', 'match');
$builder->orNotHavingLike('body', 'match');
// HAVING `title` LIKE '%match% OR  `body` NOT LIKE '%match%' ESCAPE '!'

결과 정렬

OrderBy

$builder->orderBy()

ORDER BY 절을 설정합니다.

첫 번째 매개 변수에는 정렬하려는 열(column) 이름이 포함됩니다.

두 번째 매개 변수를 사용하면 정렬 방향을 설정할 수 있습니다. 값은 ASC, DESC, RANDOM

<?php

$builder->orderBy('title', 'DESC');
// Produces: ORDER BY `title` DESC

첫 번째 매개 변수에 사용자 정의 문자열을 전달할 수도 있습니다

<?php

$builder->orderBy('title DESC, name ASC');
// Produces: ORDER BY `title` DESC, `name` ASC

여러개의 필드가 필요한 경우 함수를 여러번 호출할 수 있습니다.

<?php

$builder->orderBy('title', 'DESC');
$builder->orderBy('name', 'ASC');
// Produces: ORDER BY `title` DESC, `name` ASC

방향 옵션을 RANDOM으로 할 때 숫자로 지정하지 않으면 첫 번째 매개 변수가 무시됩니다.

<?php

$builder->orderBy('title', 'RANDOM');
// Produces: ORDER BY RAND()

$builder->orderBy(42, 'RANDOM');
// Produces: ORDER BY RAND(42)

결과 제한(Limit) 또는 카운팅(Counting)

Limit

$builder->limit()

쿼리에서 반환하려는 행 수를 제한할 수 있습니다

<?php

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

두 번째 매개 변수를 사용하면 결과 오프셋을 설정할 수 있습니다.

<?php

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

$builder->countAllResults()

쿼리 빌더를 통해 조건에 맞는 행의 갯수를 반환합니다. where(), orWhere(), like(), orLike()등과 같은 쿼리 빌더 메소드를 허용합니다.

<?php

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

그러나 이 메소드는 select()에 전달했을 수 있는 모든 필드 값을 재설정합니다. 유지하고 싶다면 첫 번째 매개 변수로 false를 전달합니다.

<?php

echo $builder->countAllResults(false); // Produces an integer, like 17

$builder->countAll()

특정 테이블의 모든 행의 갯수를 반환니다.

<?php

echo $builder->countAll(); // Produces an integer, like 25

countAllResult() 메소드와 마찬가지로 이 메소드도 select()에 전달되었을 수 있는 모든 필드 값을 재설정합니다. 유지하고 싶다면 첫 번째 매개 변수로 false를 전달합니다.

Union queries

Union

$builder->union()

둘 이상의 SELECT 문의 결과 집합을 결합하는 데 사용됩니다. 고유한 결과만 반환합니다.

<?php

$builder = $db->table('users')->select('id, name')->limit(10);
$union   = $db->table('groups')->select('id, name');
$builder->union($union)->get();
/*
 * Produces:
 * SELECT * FROM (SELECT `id`, `name` FROM `users` LIMIT 10) uwrp0
 * UNION SELECT * FROM (SELECT `id`, `name` FROM `groups`) uwrp1
 */

Note

DBMS(예: MSSQL 및 Oracle)의 올바른 작업을 위해 쿼리는 SELECT * FROM ( ... ) alias로 래핑됩니다. 기본 쿼리는 항상 uwrp0라는 별칭을 갖습니다. union()을 통해 추가된 각 후속 쿼리에는 별칭 uwrpN+1이 부여 됩니다.

모든 통합 쿼리는 union() 메서드가 호출된 순서에 관계없이 기본 쿼리 뒤에 추가됩니다. limit(), orderBy() 메소드는 union() 이후에 호출되더라도 기본 쿼리에 추가됩니다.

경우에 따라 쿼리 결과의 레코드 수를 정렬하거나 제한해야 할 수도 있습니다. 해결책은 $db->newQuery()를 통해 생성된 래퍼를 사용하는 것입니다. 아래 예에서는 처음 5명의 사용자 + 마지막 5명의 사용자를 얻고 결과를 id로 정렬합니다.

<?php

$union   = $db->table('users')->select('id, name')->orderBy('id', 'DESC')->limit(5);
$builder = $db->table('users')->select('id, name')->orderBy('id', 'ASC')->limit(5)->union($union);

$db->newQuery()->fromSubquery($builder, 'q')->orderBy('id', 'DESC')->get();
/*
 * Produces:
 * SELECT * FROM (
 *      SELECT * FROM (SELECT `id`, `name` FROM `users` ORDER BY `id` ASC LIMIT 5) uwrp0
 *      UNION
 *      SELECT * FROM (SELECT `id`, `name` FROM `users` ORDER BY `id` DESC LIMIT 5) uwrp1
 * ) q ORDER BY `id` DESC
 */

$builder->unionAll()

동작은 union() 메서드와 동일하지만 모든 결과가 반환됩니다.

쿼리 그룹화

Group

쿼리 그룹화를 사용하면 WHERE절 그룹을 괄호로 묶어 그룹을 만들 수 있습니다. 이를 이요하여 복잡한 WHERE절을 쿼리로 만들 수 있습니다. 중첩 그룹이 지원됩니다.

<?php

$builder->select('*')->from('my_table')
    ->groupStart()
        ->where('a', 'a')
        ->orGroupStart()
            ->where('b', 'b')
            ->where('c', 'c')
        ->groupEnd()
    ->groupEnd()
    ->where('d', 'd')
    ->get();
/*
 * Generates:
 * SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
 */

Note

그룹은 균형을 유지해야합니다. 모든 groupStart()groupEnd()와 쌍으로 일치하는지 확인하십시오.

$builder->groupStart()

쿼리의 WHERE절에 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->orGroupStart()

쿼리의 WHERE절에 OR 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->notGroupStart()

쿼리의 WHERE절에 NOT 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->orNotGroupStart()

쿼리의 WHERE절에 OR NOT 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->groupEnd()

쿼리의 WHERE절에 닫는 괄호를 추가하여 현재 그룹을 종료합니다.

$builder->havingGroupStart()

쿼리의 HAVING절에 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->orHavingGroupStart()

쿼리의 HAVING절에 OR 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->notHavingGroupStart()

쿼리의 HAVING절에 NOT 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->orNotHavingGroupStart()

쿼리의 HAVING절에 OR NOT 접두사와 함께 여는 괄호를 추가하여 새 그룹을 시작합니다.

$builder->havingGroupEnd()

쿼리의 HAVING절에 닫는 괄호를 추가하여 현재 그룹을 종료합니다.

Inserting 데이타

Insert

$builder->insert()

제공한 데이터를 기반으로 Insert 문자열을 생성하고 쿼리를 실행합니다. 배열 또는 객체(object)를 메소드에 전달할 수 있습니다. 다음은 배열을 사용하는 예입니다

<?php

$data = [
    'title' => 'My title',
    'name'  => 'My Name',
    'date'  => 'My date',
];

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

첫 번째 매개 변수는 값의 연관 배열입니다.

다음은 객체를 사용하는 예입니다

<?php

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

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

첫 번째 매개 변수는 객체입니다.

Note

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

$builder->ignore()

제공한 데이터를 기반으로 인서트 무시 문자열(insert ignore string)을 생성하고 쿼리를 실행합니다. 따라서 동일한 기본 키를 가진 항목이 이미 있으면 쿼리가 인서트(insert)되지 않습니다. 선택적으로 boolean을 메소드에 전달할 수 있습니다. insertBatch, update, delete(지원되는 경우)에서도 사용할 수 있습니다.

위 예제의 배열을 사용한 예제입니다.

<?php

$data = [
    'title' => 'My title',
    'name'  => 'My Name',
    'date'  => 'My date',
];

$builder->ignore(true)->insert($data);
// Produces: INSERT OR IGNORE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

$builder->getCompiledInsert()

$builder->insert()와 같이 Insert 쿼리를 컴파일하지만 쿼리를 실행하지는 않습니다. 이 메소드는 SQL 쿼리를 문자열로 반환합니다.

<?php

$data = [
    'title' => 'My title',
    'name'  => 'My Name',
    'date'  => 'My date',
];

$sql = $builder->set($data)->getCompiledInsert();
echo $sql;
// Produces string: INSERT INTO mytable (`title`, `name`, `date`) VALUES ('My title', 'My name', 'My date')

첫 번째 매개 변수를 사용하면 쿼리 빌더의 쿼리를 재설정할 지 여부를 설정할 수 있습니다. (기본적으로 $builder->insert()와 같습니다)

<?php

echo $builder->set('title', 'My Title')->getCompiledInsert(false);
// Produces string: INSERT INTO mytable (`title`) VALUES ('My Title')

echo $builder->set('content', 'My Content')->getCompiledInsert();
// Produces string: INSERT INTO mytable (`title`, `content`) VALUES ('My Title', 'My Content')

두 번째 쿼리가 작동한 이유는 첫 번째 매개변수가 false로 설정되었기 때문입니다.

Note

이 방법은 insertBatch() 에서는 작동하지 않습니다.

insertBatch

$builder->insertBatch()

제공한 데이터를 기반으로 Insert 문자열을 생성하고 쿼리를 실행합니다. 배열 또는 객체(object)를 함수에 전달할 수 있습니다. 다음은 배열을 사용하는 예입니다

<?php

$data = [
    [
        'title' => 'My title',
        'name'  => 'My Name',
        'date'  => 'My date',
    ],
    [
        'title' => 'Another title',
        'name'  => 'Another Name',
        'date'  => 'Another date',
    ],
];

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

첫 번째 매개 변수는 값의 연관 배열입니다.

Note

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

Updating 데이타

Update

$builder->replace()

이 메소드는 기본적으로 PRIMARYUNIQUE 키를 기준으로 DELETE + INSERT에 대한 SQL 표준인 REPLACE문을 실행합니다. 이것으로 당신은 select(), update(), delete(), insert()의 조합으로 구성된 복잡한 논리를 구현할 필요가 없어집니다.

<?php

$data = [
    'title' => 'My title',
    'name'  => 'My Name',
    'date'  => 'My date',
];

$builder->replace($data);
// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

위의 예에서 title 필드가 기본 키라고 가정하면 title 값으로 ‘My title’이 포함된 행은 새 행 데이터로 대체되어 삭제됩니다.

set() 메소드 사용도 허용되며 insert()와 마찬가지로 모든 값(value)은 자동으로 이스케이프됩니다.

$builder->set()

이 메소드를 사용하면 Insert 또는 Update 값을 설정할 수 있습니다.

데이터 배열을 직접 Insert() 또는 Update() 메소드로 전달하는 대신 사용할 수 있습니다.

<?php

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

여러번 사용하는 경우 Insert 또는 Update 수행 여부에 따라 올바르게 조립됩니다.

<?php

$builder->set('name', $name);
$builder->set('title', $title);
$builder->set('status', $status);
$builder->insert();

set()은 옵션으로 세 번째 매개 변수 ($escape)도 허용하며 이 값을 false로 설정하면 값(value)은 이스케이프되지 않습니다. 차이점을 설명하기 위해 다음 예제는 이스케이프 매개 변수를 사용하거나 사용하지 않고 set()을 사용합니다.

<?php

$builder->set('field', 'field+1', false);
$builder->where('id', 2);
$builder->update();
// gives UPDATE mytable SET field = field+1 WHERE `id` = 2

$builder->set('field', 'field+1');
$builder->where('id', 2);
$builder->update();
// gives UPDATE `mytable` SET `field` = 'field+1' WHERE `id` = 2

이 메소드에 연관 배열을 전달할 수 있습니다

<?php

$array = [
    'name'   => $name,
    'title'  => $title,
    'status' => $status,
];

$builder->set($array);
$builder->insert();

또는 객체

<?php

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

$object = new Myclass();
$builder->set($object);
$builder->insert();

$builder->update()

업데이트 문자열을 생성하고 제공한 데이터를 기반으로 쿼리를 실행합니다. 배열 또는 객체를 함수에 전달할 수 있습니다. 다음은 배열을 사용하는 예입니다

<?php

$data = [
    'title' => $title,
    'name'  => $name,
    'date'  => $date,
];

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

또는 객체를 제공할 수 있습니다.

<?php

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

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

Note

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

$builder->where() 함수를 사용하면 WHERE절을 설정할 수 있습니다. 선택적으로 이 정보를 문자열로 update() 메소드에 직접 전달할 수 있습니다

<?php

$builder->update($data, 'id = 4');

또는 배열로

<?php

$builder->update($data, ['id' => $id]);

업데이트를 수행할 때 위에서 설명한 $builder->set() 메소드를 사용할 수도 있습니다.

UpdateBatch

$builder->updateBatch()

업데이트 문자열을 생성하고 제공한 데이터를 기반으로 쿼리를 실행합니다. 배열 또는 객체를 메소드에 전달할 수 있습니다. 다음은 배열을 사용하는 예입니다

<?php

$data = [
    [
        'title' => 'My title',
        'name'  => 'My Name 2',
        'date'  => 'My date 2',
    ],
    [
        'title' => 'Another title',
        'name'  => 'Another Name 2',
        'date'  => 'Another date 2',
    ],
];

$builder->updateBatch($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

affectedRows()는 작동 방식이 달라 이 메소드에 대한 적절한 결과를 제공하지 않습니다. 대신 updateBatch()는 영향을 받는 행 수를 반환합니다.

$builder->getCompiledUpdate()

이것은 INSERT SQL 문자열대신 UPDATE SQL 문자열을 생성한다는 점을 제외하고 $builder->getCompiledInsert()와 동일한 방식으로 작동합니다.

자세한 내용은 $builder->getCompiledInsert()에 대한 설명서를 참조하십시오.

Note

updateBatch()는 이 메소드가 작동하지 않습니다.

데이터 삭제(Deleting)

Delete

$builder->delete()

DELETE SQL 문자열을 생성하고 쿼리를 실행합니다.

<?php

$builder->delete(['id' => $id]);
// Produces: DELETE FROM mytable WHERE id = $id

첫 번째 매개 변수는 where절입니다. 함수의 첫 번째 매개 변수에 데이터를 전달하는 대신 where() 또는 orWhere() 메소드를 사용할 수 있습니다.

<?php

$builder->where('id', $id);
$builder->delete();
/*
 * Produces:
 * DELETE FROM mytable
 * WHERE id = $id
 */

테이블에서 모든 데이터를 삭제하려면 truncate() 함수 또는 emptyTable() 메소드를 사용합니다.

$builder->emptyTable()

DELETE SQL 문자열을 생성하고 쿼리를 실행합니다.

<?php

$builder->emptyTable('mytable');
// Produces: DELETE FROM mytable

$builder->truncate()

TRUNCATE SQL 문자열을 생성하고 쿼리를 실행합니다.

<?php

$builder->truncate();
/*
 * Produce:
 * TRUNCATE mytable
 */

Note

TRUNCATE 명령을 사용할 수 없으면 truncate()가 “DELETE FROM table”로 실행됩니다.

$builder->getCompiledDelete()

이것은 INSERT SQL 문자열 대신 DELETE SQL 문자열을 생성한다는 점을 제외하고 $builder->getCompiledInsert()와 동일한 방식으로 작동합니다.

자세한 내용은 $builder->getCompiledInsert() 설명서를 참조하십시오.

메소드 체이닝(Chaining)

메소드 체인을 사용하면 여러 메소드를 연결하여 구문을 단순화 할 수 있습니다. 다음 예제를 살펴보십시오.

<?php

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

쿼리 빌더 재설정

ResetQuery

$builder->resetQuery()

쿼리 빌더를 재 설정하면 $builder->get() 또는 $builder->insert()와 같은 메소드를 사용하여 쿼리를 실행하지 않고 쿼리를 새로 시작할 수 있습니다.

이는 쿼리 빌더를 사용하여 SQL을 생성(ex. $builder->getCompiledSelect())한 후 다음 작업을 진행시 유용합니다.

<?php

// Note that the second parameter of the ``get_compiled_select`` method is false
$sql = $builder->select(['field1', 'field2'])
    ->where('field3', 5)
    ->getCompiledSelect(false);

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

$data = $builder->get()->getResultArray();
/*
 * Would execute and return an array of results of the following query:
 * SELECT field1, field1 from mytable where field3 = 5;
 */

Class Reference

class CodeIgniter\Database\BaseBuilder
db()
Returns

사용중인 데이터베이스 연결

Return type

ConnectionInterface

연결된 데이터베이스 객체를 $db로 반환합니다. insertID()errors()와 같이 쿼리빌더(Query Builder)에서 직접 사용할 수 없는 ConnectionInterface 메소드를 액세스할 때 유용합니다.

resetQuery()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

쿼리 빌더 상태를 재설정합니다. 특정 조건에서 쿼리를 작성 취소하려는 경우에 유용합니다.

countAllResults([$reset = true])
Parameters
  • $reset (bool) – SELECT 재설정 여부

Returns

쿼리 결과의 행의 갯수

Return type

int

쿼리 빌더를 통하여 반환한 모든 레코드를 수를 계산하는 플랫폼별 쿼리 문자열을 생성 실행합니다.

countAll([$reset = true])
Parameters
  • $reset (bool) – SELECT 재설정 여부

Returns

쿼리 결과의 행의 갯수

Return type

int

쿼리 빌더를 통하여 반환한 모든 레코드를 수를 계산하는 플랫폼별 쿼리 문자열을 생성 실행합니다.

get([$limit = null[, $offset = null[, $reset = true]]]])
Parameters
  • $limit (int) – LIMIT 절

  • $offset (int) – OFFSET 절

  • $reset (bool) – 쿼리 빌더 값 재설정 여부

Returns

\CodeIgniter\Database\ResultInterface instance (method chaining)

Return type

\CodeIgniter\Database\ResultInterface

호출된 쿼리 빌더 메소드를 기반으로 SELECT 문을 컴파일하고 실행합니다.

getWhere([$where = null[, $limit = null[, $offset = null[, $reset = true]]]]])
Parameters
  • $where (string) – WHERE 절

  • $limit (int) – LIMIT 절

  • $offset (int) – OFFSET 절

  • $reset (bool) – 쿼리 빌더 값 재설정 여부

Returns

\CodeIgniter\Database\ResultInterface instance (method chaining)

Return type

\CodeIgniter\Database\ResultInterface

get()과 동일하지만 WHERE를 직접 추가할 수 있습니다.

select([$select = '*'[, $escape = null]])
Parameters
  • $select (array|RawSql|string) – 쿼리의 SELECT 부분

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectAvg([$select = ''[, $alias = '']])
Parameters
  • $select (string) – 평균을 계산하는 필드

  • $alias (string) – 결과 값 이름의 별명

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectMax([$select = ''[, $alias = '']])
Parameters
  • $select (string) – 최대 값을 계산하는 필드

  • $alias (string) – 결과 값 이름의 별명

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectMin([$select = ''[, $alias = '']])
Parameters
  • $select (string) – 최소 값을 계산하는 필드

  • $alias (string) – 결과 값 이름의 별명

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectSum([$select = ''[, $alias = '']])
Parameters
  • $select (string) – 합계를 계산하는 필드

  • $alias (string) – 결과 값 이름의 별명

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectCount([$select = ''[, $alias = '']])
Parameters
  • $select (string) – 카운트할 필드

  • $alias (string) – 결과 값 이름의 별명

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

selectSubquery(BaseBuilder $subquery, string $as)
Parameters
  • $subquery (string) – BaseBuilder 인스턴스

  • $as (string) – 결과 값 이름의 별칭

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

선택 항목에 서브쿼리를 추가합니다.

distinct([$val = true])
Parameters
  • $val (bool) – “distinct” 플래그 설정 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

쿼리 빌더가 DISTINCT 절을 쿼리의 SELECT 부분에 추가하도록 지시하는 플래그를 설정합니다.

from($from[, $overwrite = false])
Parameters
  • $from (mixed) – 테이블 명; string 또는 array

  • $overwrite (bool) – 기존 설정된 첫 번째 테이블 제거 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

fromSubquery($from, $alias)
Parameters
  • $from (BaseBuilder) – BaseBuilder class의 인스턴스

  • $alias (string) – 서브쿼리 별칭

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

Specifies the FROM clause of a query using a subquery.

join($table, $cond[, $type = ''[, $escape = null]])
Parameters
  • $table (string) – 결합(Join)할 테이블 이름

  • $cond (string) – JOIN ON 조건

  • $type (string) – JOIN type

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

where($key[, $value = null[, $escape = null]])
Parameters
  • $key (mixed) – 비교할 필드 이름 또는 연관 배열

  • $value (mixed) – 단일 키인 경우 이 값과 비교

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

쿼리의 WHERE 부분을 생성합니다. 여러번 호출할 경우 ‘AND’로 연결합니다.

orWhere($key[, $value = null[, $escape = null]])
Parameters
  • $key (array|RawSql|string) – 비교할 필드 이름 또는 연관 배열

  • $value (mixed) – 단일 키인 경우 이 값과 비교

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

쿼리의 WHERE 부분을 생성합니다. 여러번 호출할 경우 ‘OR’로 연결합니다.

orWhereIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검색할 필드

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리의 WHERE field IN(‘item’, ‘item’) 부분을 생성합니다. ‘OR’로 연결합니다.

orWhereNotIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검색할 필드

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리의 WHERE field NOT IN(‘item’, ‘item’) 부분을 생성합니다. ‘OR’로 연결합니다.

whereIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검사 할 필드 이름

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리의 WHERE field IN(‘item’, ‘item’) 부분을 생성합니다. ‘AND’로 연결합니다.

whereNotIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검사 할 필드 이름

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리의 WHERE field NOT IN(‘item’, ‘item’) 부분을 생성합니다. ‘AND’로 연결합니다.

groupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

AND를 사용하여 그룹 표현식을 시작합니다.

orGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

OR을 사용하여 그룹 표현식을 시작합니다.

notGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

AND NOT을 사용하여 그룹 표현식을 시작합니다.

orNotGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

OR NOT을 사용하여 그룹 표현식을 시작합니다.

groupEnd()
Returns

BaseBuilder instance (method chaining)

Return type

object

그룹 표현식을 종료합니다.

like($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (array|RawSql|string) – Field name

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 AND를 사용하여 LIKE 절을 쿼리에 추가합니다.

orLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 OR을 사용하여 LIKE 절을 쿼리에 추가합니다.

notLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 AND를 사용하여 NOT LIKE 절을 쿼리에 추가합니다.

orNotLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 OR을 사용하여 NOT LIKE 절을 쿼리에 추가합니다.

having($key[, $value = null[, $escape = null]])
Parameters
  • $key (mixed) – 필드/값 쌍의 식별자(문자열) 또는 연관 배열

  • $value (string) – Value sought if $key is an identifier

  • $escape (string) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 AND를 사용하여 HAVING 절을 쿼리에 추가합니다.

orHaving($key[, $value = null[, $escape = null]])
Parameters
  • $key (mixed) – 필드/값 쌍의 식별자(문자열) 또는 연관 배열

  • $value (string) – Value sought if $key is an identifier

  • $escape (string) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 OR을 사용하여 HAVING 절을 쿼리에 추가합니다.

orHavingIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검색할 필드

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리에 HAVING field IN(‘item’, ‘item’) 절을 추가합니다. OR로 분리.

orHavingNotIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검색할 필드

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리에 HAVING field NOT IN(‘item’, ‘item’) 절을 추가합니다. OR로 분리.

havingIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검사 할 필드 이름

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리에 HAVING field IN(‘item’, ‘item’) 절을 추가합니다. AND로 분리.

havingNotIn([$key = null[, $values = null[, $escape = null]]])
Parameters
  • $key (string) – 검사 할 필드 이름

  • $values (array|BaseBulder|Closure) – 대상 값 배열 또는 서브 쿼리에 대한 익명 함수

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance

Return type

object

SQL 쿼리에 HAVING field NOT IN(‘item’, ‘item’) 절을 추가합니다. AND로 분리.

havingLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 AND를 사용하여 HAVING 부분에 LIKE 절을 쿼리에 추가합니다.

orHavingLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 OR을 사용하여 HAVING 부분에 LIKE 절을 쿼리에 추가합니다.

notHavingLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

  • $insensitiveSearch (bool) – 대소문자를 구분하지 않고 검색할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 AND를 사용하여 HAVING 부분에 NOT LIKE 절을 쿼리에 추가합니다.

orNotHavingLike($field[, $match = ''[, $side = 'both'[, $escape = null[, $insensitiveSearch = false]]]])
Parameters
  • $field (string) – 필드명

  • $match (string) – 일치할 텍스트 부분

  • $side (string) – 와일드 카드(%)를 넣을 위치

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

여러번 호출할 경우 OR을 사용하여 HAVING 부분에 NOT LIKE 절을 쿼리에 추가합니다.

havingGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

AND를 사용하여 HAVING 절에 대한 그룹 표현식을 시작합니다.

orHavingGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

OR을 사용하여 HAVING 절에 대한 그룹 표현식을 시작합니다.

notHavingGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

AND NOT을 사용하여 HAVING 절에 대한 그룹 표현식을 시작합니다.

orNotHavingGroupStart()
Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

OR NOT을 사용하여 HAVING 절에 대한 그룹 표현식을 시작합니다.

havingGroupEnd()
Returns

BaseBuilder instance

Return type

object

HAVING 절에 대한 그룹 표현식을 종료합니다.

groupBy($by[, $escape = null])
Parameters
  • $by (mixed) – Field(s) to group by; string or array

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

orderBy($orderby[, $direction = ''[, $escape = null]])
Parameters
  • $orderby (string) – 정렬할 필드

  • $direction (string) – The order requested - ASC, DESC or random

  • $escape (bool) – 값과 식별자를 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

limit($value[, $offset = 0])
Parameters
  • $value (int) – 결과를 제한할 행 수

  • $offset (int) – 건너 뛸 행 수

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

offset($offset)
Parameters
  • $offset (int) – 건너 뛸 행 수

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

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

union($union)
Parameters
  • $union (BaseBulder|Closure) – Union 쿼리

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

UNION절을 추가합니다.

unionAll($union)
Parameters
  • $union (BaseBulder|Closure) – Union 쿼리

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

UNION ALL절을 추가합니다.

set($key[, $value = ''[, $escape = null]])
Parameters
  • $key (mixed) – 필드 이름 또는 필드/값 쌍 배열

  • $value (string) – $key가 단일 필드인 경우 필드 값

  • $escape (bool) – 값을 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

insert(), update(), replace()에 전달할 필드/값 쌍을 추가합니다.

insert([$set = null[, $escape = null]])
Parameters
  • $set (array) – 필드/값 쌍 배열

  • $escape (bool) – 값을 이스케이프할지 여부

Returns

true on success, false on failure

Return type

bool

INSERT 문을 컴파일하고 실행합니다.

insertBatch([$set = null[, $escape = null[, $batch_size = 100]]])
Parameters
  • $set (array) – Insert할 데이터

  • $escape (bool) – 값을 이스케이프할지 여부

  • $batch_size (int) – 한 번에 Insert할 행의 수

Returns

Insert된 행의 수, 실패시 false

Return type

mixed

배치 INSERT문을 컴파일하고 실행합니다.

Note

$batch_size 이상의 행이 제공되면, 각각 $batch_size 행을 Insert하려고 하는 여러 INSERT 쿼리가 실행됩니다.

setInsertBatch($key[, $value = ''[, $escape = null]])
Parameters
  • $key (mixed) – 필드 이름 또는 필드/값 쌍 배열

  • $value (string) – $key가 단일 필드인 경우 필드 값

  • $escape (bool) – 값을 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

insertBatch()를 통해 테이블에 Insert할 필드/값 쌍을 추가합니다.

update([$set = null[, $where = null[, $limit = null]]])
Parameters
  • $set (array) – 필드/값 쌍의 연관 배열

  • $where (string) – WHERE 절

  • $limit (int) – LIMIT 절

Returns

true on success, false on failure

Return type

bool

UPDATE 문을 컴파일하고 실행합니다.

updateBatch([$set = null[, $value = null[, $batch_size = 100]]])
Parameters
  • $set (array) – 필드 이름 또는 필드/값 쌍의 연관 배열

  • $value (string) – $set가 단일 필드인 경우 필드 값

  • $batch_size (int) – 단일 쿼리에 그룹화할 조건 수입니다.

Returns

업데이트된 행 수 또는 실패 시 false입니다.

Return type

mixed

배치 UPDATE문을 컴파일하고 실행합니다.

Note

$batch_size 이상의 필드/값 쌍이 제공되면 각각 $batch_size 필드/값 쌍을 Update하는 여러 쿼리가 실행됩니다.

setUpdateBatch($key[, $value = ''[, $escape = null]])
Parameters
  • $key (mixed) – 필드 이름 또는 필드/값 쌍 배열

  • $value (string) – $key가 단일 필드인 경우 필드 값

  • $escape (bool) – 값을 이스케이프할지 여부

Returns

BaseBuilder instance (method chaining)

Return type

BaseBuilder

updateBatch()를 통해 테이블에서 업데이트할 필드/값 쌍을 추가합니다.

replace([$set = null])
Parameters
  • $set (array) – 필드/값 쌍의 연관 배열

Returns

true on success, false on failure

Return type

bool

REPLACE 문을 컴파일하고 실행합니다.

delete([$where = ''[, $limit = null[, $reset_data = true]]])
Parameters
  • $where (string) – WHERE 절

  • $limit (int) – LIMIT 절

  • $reset_data (bool) – 쿼리 “write” 절을 재설정하려면 true

Returns

BaseBuilder instance (method chaining) or false on failure

Return type

mixed

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

increment($column[, $value = 1])
Parameters
  • $column (string) – 증가시킬 열(column)의 이름

  • $value (int) – 증가시키는 양

필드 값을 지정된 양만큼 증가시킵니다. 필드가 VARCHAR와 같은 숫자 필드가 아닌 경우 $value로 대체될 수 있습니다.

decrement($column[, $value = 1])
Parameters
  • $column (string) – 감소시킬 열(column)의 이름

  • $value (int) – 감소시키는 양

필드 값을 지정된 양만큼 감소시킵니다. 필드가 VARCHAR와 같은 숫자 필드가 아닌 경우 $value로 대체될 수 있습니다.

truncate()
Returns

true on success, false on failure

Return type

bool

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

Note

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

emptyTable()
Returns

true on success, false on failure

Return type

bool

DELETE 문을 통해 테이블에서 모든 레코드를 삭제합니다.

getCompiledSelect([$reset = true])
Parameters
  • $reset (bool) – 현재 QB 값을 재설정할지 여부

Returns

컴파일된 SQL 문의 문자열

Return type

string

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

getCompiledInsert([$reset = true])
Parameters
  • $reset (bool) – 현재 QB 값을 재설정할지 여부

Returns

컴파일된 SQL 문의 문자열

Return type

string

INSERT 문을 컴파일하여 문자열로 리턴합니다.

getCompiledUpdate([$reset = true])
Parameters
  • $reset (bool) – 현재 QB 값을 재설정할지 여부

Returns

컴파일된 SQL 문의 문자열

Return type

string

UPDATE 문을 컴파일하여 문자열로 리턴합니다.

getCompiledDelete([$reset = true])
Parameters
  • $reset (bool) – 현재 QB 값을 재설정할지 여부

Returns

컴파일된 SQL 문의 문자열

Return type

string

DELETE 문을 컴파일하여 문자열로 리턴합니다.