~bohwaz/blog/

Avec de vrais morceaux de 2.0 !

PHP & SQLite3 : collation

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 ;-)

Write a comment
(optional)
(optional)
(mandatory)
                   _               
  __ _ _ __   __ _(_)___  ___ _ __ 
 / _` | '_ \ / _` | / __|/ _ \ '__|
| (_| | |_) | (_| | \__ \  __/ |   
 \__,_| .__/ \__,_|_|___/\___|_|   
      |_|                          
(mandatory)

URLs will create links automatically.
Allowed HTML tags: <blockquote> <cite> <pre> <code> <var> <strong> <em> <del> <ins> <kbd> <samp> <abbr>