本文整理汇总了PHP中SQLite3::createCollation方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLite3::createCollation方法的具体用法?PHP SQLite3::createCollation怎么用?PHP SQLite3::createCollation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite3
的用法示例。
在下文中一共展示了SQLite3::createCollation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
<?php
require_once 'header.html';
require_once 'rb.php';
R::setup('sqlite:./db/directory.db');
$db = new SQLite3('./db/directory.db');
$db->createCollation('NV', function ($a, $b) {
$a = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $a);
$b = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $b);
return strcmp($a, $b);
});
?>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<div class="pull-right"><p class="lead">Izberite prvo črko priimka</p></div>
<h1>Imenik stanovalcev</h1>
</div>
<?php
$stmt = $db->prepare('SELECT DISTINCT substr(surname, 1,1) as letter FROM person ORDER BY letter COLLATE NV');
$result = $stmt->execute();
while ($letter = $result->fetchArray()) {
echo '<a href="letter.php?l=' . $letter["letter"] . '" class="btn btn-default btn-letter">' . $letter["letter"] . '</a>';
}
?>
</div>
<?php
require_once 'footer.html';
示例2: oopsFunction
<?php
function oopsFunction($a, $b)
{
echo "callback" . PHP_EOL;
throw new \Exception("oops");
}
$db = new SQLite3(":memory:");
$db->exec("CREATE TABLE test (col1 string)");
$db->exec("INSERT INTO test VALUES ('a1')");
$db->exec("INSERT INTO test VALUES ('a10')");
$db->exec("INSERT INTO test VALUES ('a2')");
try {
$db->createCollation('NATURAL_CMP', 'oopsFunction');
$naturalSort = $db->query("SELECT col1 FROM test ORDER BY col1 COLLATE NATURAL_CMP");
while ($row = $naturalSort->fetchArray()) {
echo $row['col1'], "\n";
}
$db->close();
} catch (\Exception $e) {
echo "Exception: " . $e->getMessage();
}