PDO::sqliteCreateCollation

(PHP 5 >= 5.3.11, PHP 7)

PDO::sqliteCreateCollation Registers a User Defined Function for use as a collating function in SQL statements

说明

public PDO::sqliteCreateCollation ( string $name , callable $callback ) : bool
Warning

此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担 。

参数

name

Name of the SQL collating function to be created or redefined.

callback

The name of a PHP function or user-defined function to apply as a callback, defining the behavior of the collation. It should accept two strings and return as strcmp() does, i.e. it should return -1, 1, or 0 if the first string sorts before, sorts after, or is equal to the second.

This function need to be defined as:

collation ( string $string1 , string $string2 ) : int

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 PDO::sqliteCreateCollation() example

<?php
$db 
= new PDO('sqlite::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')");

$db->sqliteCreateCollation('NATURAL_CMP''strnatcmp');
foreach (
$db->query("SELECT col1 FROM test ORDER BY col1") as $row) {
  echo 
$row['col1'] . "\n";
}
echo 
"\n";
foreach (
$db->query("SELECT col1 FROM test ORDER BY col1 COLLATE NATURAL_CMP") as $row) {
  echo 
$row['col1'] . "\n";
}
?>

以上例程会输出:

a1
a10
a2

a1
a2
a10

注释

Note:

This method is not available with the SQLite2 driver. Use the old style sqlite API for that instead.

相关文章
php arrayiterator sort with a user defined comparison function and maintain index associationphp arrayiterator sort by keys using a user defined comparison functionphp arrayobject sort the entries with a user defined comparison function and maintain key associationphp arrayobject sort the entries by keys using a user defined comparison functionphp fdf 函数 call a user defined function for each document valuephp mysqlnd qc 函数 sets the callback functions for a user defined procedural storage handlerphp oci8 函数 register a user defined callback function for oracle database tafphp oci8 函数 unregister a user defined callback function for oracle database tafphp sqlite 函数 register an aggregating udf for use in sql statementsphp sqlite 函数 registers a regular user defined function for use in sql statementsphp sqlite 函数 escapes a string for use as a query parameterphp pdo 执行一条 sql 语句,并返回受影响的行数php pdo 执行 sql 语句,以 pdostatement 对象形式返回结果集php sqlite pdo registers an aggregating user defined function for use in sql statementsphp sqlite pdo registers a user defined function for use as a collating function in sql statementsphp sqlite pdo registers a user defined function for use in sql statementsphp 4d pdo connecting to 4d sql serverphp sqlite3 registers a php function for use as an sql aggregate functionphp sqlite3 registers a php function for use as an sql collating functionphp sqlite3 registers a php function for use as an sql scalar function
关注编程学问公众号