PROJET AUTOBLOG


BohwaZ

Site original : BohwaZ

⇐ retour index

PHP & SQLite3 : collation

mardi 28 février 2012 à 15:59

In PHP 5.3 there is no way to define a custom collation method for SQLite3.

But here is another reason to use PHP 5.4: it will provide new methods to have user-defined collation. For SQLite3 object it will be SQLite3::createCollation(name, callback), and there will be also a similar method for PDO::SQLite.

Its use is very easy:

$db = new SQLite3('data.db');
setlocale(LC_COLLATE, 'fr_FR.UTF-8');
$db->createCollation('PHP_COLLATE', 'strcoll');
$db->query('SELECT * FROM table ORDER BY name COLLATE PHP_COLLATE;');

Great, isn't it? Well just wait until PHP 5.4 release ;-)