Thank's Swithun

but I still have trouble.

Ok, I find out how to register functions with PDO_Sqlite extensions. Just in
case someone is in the same situation, the way to do it is this:

$dbh = new PDO('sqlite:/whatever.sqlite');
$dbh->sqliteCreateFunction('Test','Test');

But I still have a problem:

If I use direct the test funcion in a quuery like

$res=$dbh->query("select test() from table");

it works, but if function test is invoked from a triiger it will say, my
sentence will be somethin like

$modulo=$dbh->query("UPDATE test SET x = 1");

I get this:

    [0] => HY000
    [1] => 1
    [2] => no such function: Test

seems like the trigger is not using the same "$dbh"

¿any clue?

Thx

2009/8/28 Swithun Crowe <swit...@swithun.servebeer.com>

> Hello
>
> AR if I run this php script
> AR
> AR *$dbh = new PDO('sqlite:/var/www/test.sqlite');
> AR $sql="INSERT INTO Test ( Nombre , IP , MAC , Descripcion_Modulo ) VALUES
> (
> AR '2221' , '2121' , '1212' , '1212' ) ";
> AR $modulo=$dbh->query($sql);
> AR print_r($dbh->errorInfo()); *
> AR
> AR from outside SQLiteManager I get this errorInfo():
> AR
> AR *Array
> AR (
> AR     [0] => HY000
> AR     [1] => 1
> AR     [2] => no such function: test
> AR )*
>
> Being able to execute PHP functions from inside SQL is a bit of a bonus
> feature. I imagine that PDO, which implements a subset of many SQL
> databases' features, doesn't reach this far.
>
> If you use the SQLite3 extension in PHP, you can register your own
> functions. You would create the function in your PHP source, and then
> register it when you open the database, and then call it from your SQL
> statements.
>
> Perhaps you could keep your "user_function" table, and query it to get the
> PHP code for each function, eval it somehow and then register it with the
> database connection.
>
> There is more here:
>
> http://www.php.net/manual/en/sqlite3.createfunction.php
>
> I hope this helps.
>
> Swithun.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to