Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test SQLite3::createCollation() by adding strnatcmp() as an SQL COLLATE sequence ..

Decoded Output download

--TEST--
Test SQLite3::createCollation() by adding strnatcmp() as an SQL COLLATE sequence
--EXTENSIONS--
sqlite3
--FILE--
<?php

require_once __DIR__ .  '/new_db.inc';

$db->createCollation('NAT', 'strnatcmp');

$db->exec('CREATE TABLE t (s varchar(4))');

$stmt = $db->prepare('INSERT INTO t VALUES (?)');
foreach(array('a1', 'a10', 'a2') as $s){
    $stmt->bindParam(1, $s);
    $stmt->execute();
}

$defaultSort = $db->query('SELECT s FROM t ORDER BY s');             //memcmp() sort
$naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); //strnatcmp() sort

echo "default
";
while ($row = $defaultSort->fetchArray()){
    echo $row['s'], "
";
}

echo "natural
";
while ($row = $naturalSort->fetchArray()){
    echo $row['s'], "
";
}

$db->close();

?>
--EXPECT--
default
a1
a10
a2
natural
a1
a2
a10

Did this file decode correctly?

Original Code

--TEST--
Test SQLite3::createCollation() by adding strnatcmp() as an SQL COLLATE sequence
--EXTENSIONS--
sqlite3
--FILE--
<?php

require_once __DIR__ .  '/new_db.inc';

$db->createCollation('NAT', 'strnatcmp');

$db->exec('CREATE TABLE t (s varchar(4))');

$stmt = $db->prepare('INSERT INTO t VALUES (?)');
foreach(array('a1', 'a10', 'a2') as $s){
    $stmt->bindParam(1, $s);
    $stmt->execute();
}

$defaultSort = $db->query('SELECT s FROM t ORDER BY s');             //memcmp() sort
$naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); //strnatcmp() sort

echo "default\n";
while ($row = $defaultSort->fetchArray()){
    echo $row['s'], "\n";
}

echo "natural\n";
while ($row = $naturalSort->fetchArray()){
    echo $row['s'], "\n";
}

$db->close();

?>
--EXPECT--
default
a1
a10
a2
natural
a1
a2
a10

Function Calls

None

Variables

None

Stats

MD5 91d0fa3368734f691e5be6be48f8c5f8
Eval Count 0
Decode Time 93 ms