2015-03-29 17:31:31 +00:00
<?xml version="1.0" encoding="utf-8"?>
2015-03-30 08:40:32 +00:00
<!-- $Revision$ -->
2015-03-29 19:27:39 +00:00
<refentry xml:id= "pdo.sqlitecreatecollation" xmlns= "http://docbook.org/ns/docbook" >
2015-03-29 17:31:31 +00:00
<refnamediv >
<refname > PDO::sqliteCreateCollation</refname>
<refpurpose >
2015-03-30 08:56:22 +00:00
Registers a User Defined Function for use as a collating function in SQL statements
2015-03-29 17:31:31 +00:00
</refpurpose>
</refnamediv>
<refsect1 role= "description" >
&reftitle.description;
<methodsynopsis >
<modifier > public</modifier> <type > bool</type> <methodname > PDO::sqliteCreateCollation</methodname>
<methodparam > <type > string</type> <parameter > name</parameter> </methodparam>
<methodparam > <type > callable</type> <parameter > callback</parameter> </methodparam>
</methodsynopsis>
&warn.experimental.func;
</refsect1>
<refsect1 role= "parameters" >
&reftitle.parameters;
<para >
<variablelist >
<varlistentry >
<term > <parameter > name</parameter> </term>
<listitem >
<para >
2015-03-30 08:56:22 +00:00
Name of the SQL collating function to be created or redefined.
2015-03-29 17:31:31 +00:00
</para>
</listitem>
</varlistentry>
<varlistentry >
<term > <parameter > callback</parameter> </term>
<listitem >
<para >
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.
</para>
<para >
This function need to be defined as:
<methodsynopsis >
<type > int</type> <methodname > <replaceable > collation</replaceable> </methodname>
<methodparam > <type > string</type> <parameter > string1</parameter> </methodparam>
<methodparam > <type > string</type> <parameter > string2</parameter> </methodparam>
</methodsynopsis>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role= "returnvalues" >
&reftitle.returnvalues;
<para >
&return.success;
</para>
</refsect1>
<refsect1 role= "examples" >
&reftitle.examples;
<para >
<example >
<title > <function > PDO::sqliteCreateCollation</function> example</title>
<programlisting role= "php" >
< ![CDATA[
< ?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');
2015-03-30 07:25:07 +00:00
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";
}
2015-03-29 17:31:31 +00:00
?>
]]>
</programlisting>
&example.outputs;
<screen >
< ![CDATA[
2015-03-30 07:25:07 +00:00
a1
a10
a2
a1
a2
a10
2015-03-29 17:31:31 +00:00
]]>
</screen>
</example>
</para>
2015-03-30 08:56:22 +00:00
</refsect1>
<refsect1 role= "notes" >
&reftitle.notes;
2015-03-29 17:31:31 +00:00
<note >
<para >
This method is not available with the SQLite2 driver.
Use the old style sqlite API for that instead.
</para>
</note>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->