
PDOStatement에 반영되지 않는 collation의 이유는 PDOStatement을 생성할 때 collation을 설정하지 않았거나, PDOStatement을 다시 생성하지 않았기 때문입니다.
collation을 설정하려면 PDOStatement을 다시 생성하거나, PDOStatement::setFetchMode 메소드를 사용하여 fetch mode를 설정해야 합니다.
예를 들어, 'utf8_general_ci' collation을 설정하려면 다음과 같이 할 수 있습니다.
#hostingforum.kr
php
$db = new PDO('sqlite:example.db');
$db->exec('CREATE TABLE example (id INTEGER PRIMARY KEY, name TEXT)');
$db->exec('CREATE COLLATION utf8_general_ci AS "utf8_general_ci"');
$stmt = $db->prepare('SELECT * FROM example ORDER BY name COLLATE utf8_general_ci');
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
또는
#hostingforum.kr
php
$db = new PDO('sqlite:example.db');
$db->exec('CREATE TABLE example (id INTEGER PRIMARY KEY, name TEXT)');
$db->exec('CREATE COLLATION utf8_general_ci AS "utf8_general_ci"');
$stmt = $db->prepare('SELECT * FROM example ORDER BY name COLLATE utf8_general_ci');
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
2025-08-09 06:46