Statement on glibc/iconv Vulnerability

PDO::sqliteCreateCollation

(PHP 5 >= 5.3.11, PHP 7, PHP 8)

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

Descrizione

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

Questa funzione è SPERIMENTALE. Ovvero, il comportamento di questa funzione, il nome di questa funzione, in definitiva tutto ciò che è documentato qui può cambiare nei futuri rilasci del PHP senza preavviso. Siete avvisati, l'uso di questa funzione è a vostro rischio.

Elenco dei parametri

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

Valori restituiti

Restituisce true in caso di successo, false in caso di fallimento.

Esempi

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";
}
?>

Il precedente esempio visualizzerà:

a1
a10
a2

a1
a2
a10

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top