I ran into an issue in which I needed to test whether sqlite and the pdo plugin had support for UTF-8. From the documentation, sqlite3 should be able to handle this and other charsets. Further, the pdo should be charset agnostic. The following script should return UTF-8 because of the 'pound' symbol if indeed both items above are true.
try {
$dbh = new PDO("sqlite::memory:", "charset=UTF-8");
} catch(PDOException $e) {
echo $e->getMessage();
}
$sql = "create table t1 (id int, field1 varchar(255))";
try {
$dbh->exec($sql);
} catch(PDOException $e) {
echo $dbh->getMessage();
}
$sql = 'insert into t1 (id, field1) values (1, "A bit of text £")';
try {
$dbh->exec($sql);
} catch(PDOException $e) {
echo $dbh->getMessage();
}
$sql = 'select field1 from t1 where id=1';
try {
foreach ($dbh->query($sql) as $row) {
print "field1: " . $row['field1'] . "\n";
print "Encoding: " . mb_detect_encoding($row['field1']) . "\n";
}
} catch(PDOException $e) {
echo $dbh->getMessage();
}
?>
Output of the above script should look similar to the following:
field1: A bit of text £
Encoding: UTF-8
Notice the UTF-8 output due to the pound sign being used in the text string.