It appears that UDFs created by sqlite_create_function() do not work properly within INSERT or DELETE statements.
A simplified INSERT example:
<?php
// SQLite UDF
// Mimic MySQL FROM_UNIXTIME function
function from_unixtime($unixtime)
{
return "'".date('Y-m-d H:i:s', $unixtime)."'";
}
// -----------------------------------------------------------
// Open the database and create the UDF
$handle = sqlite_open('db.sqlite', 0666);
sqlite_create_function($handle, 'FROM_UNIXTIME', 'from_unixtime', 1);
// Insert a row
$sql = "
INSERT INTO table (name, timestamp)
VALUES ('Foo', FROM_UNIXTIME(".time().");
";
$result = sqlite_exec($handle, $sql);
// Retrieve the row
$sql = "SELECT * FROM table";
$result = sqlite_unbuffered_query($handle, $sql)
$row = sqlite_fetch_all($result, SQLITE_ASSOC);
// Dump
print_r($row);
?>
This will show:
Array
(
[0] => Array
(
[name] => 'Foo'
[timestamp] => -1
)
)
The expected result for timestamp would be something like '2005-05-20 10:00:00'