Yún, PHP and SQLite

Hi everybody
I installed PHP and SQLite on my Yún. I made a Python script that reads a temperature via bridge each 5 minuttes. It saves the data in a SQLite database. The Python script works as intented.
In PHP, this scripte works:

<?php
echo sqlite_libversion();
?>

I got version number 2.8.17
But this one result in

Bad Gateway

The process did not produce any response

<?php
if ($db = sqlite_open('/mnt/sda1/www/data.db', 0666, $error)) {
	$result = sqlite_query($db, "SELECT * FROM tblTempHist");
	$rows = sqlite_num_rows($result);
	echo "Number of rows: $rows";
} else {
	die($error);
}
?>

At the beginning I could not get anything but the error. Even with the libversion script. I then installed libsqlite2 and php5-mod-sqlite. I have enablet things in PHP.INI without success.

Any suggestions on where to look for this bug?

This is the working Python script:

import sched, time, sys, datetime
import sqlite3 as lite
sys.path.insert(0, '/usr/lib/python2.7/bridge/') 
from bridgeclient import BridgeClient as bridgeclient
s = sched.scheduler(time.time, time.sleep)
value = bridgeclient()                                                      
con = None
con = lite.connect('/mnt/sda1/www/data.db')
cur = con.cursor()
    
def do_something(sc): 
    sc.enter(300, 1, do_something, (sc,))
    t = value.get('TEMP')
    k = unicode(datetime.datetime.now())
    cur.execute("INSERT INTO tblTempHist VALUES('" + k + "'," + t + ");")
    con.commit()
    print k + " : " + t
    print "INSERT INTO tblTempHist VALUES('" + k + "'," + t + ");"
    
s.enter(1, 1, do_something, (s,))
s.run()

Hi again

I found some other samplecode starting like this:

<?php
   class MyDB extends SQLite3
   {
      function __construct()
      {
         $this->open('data.db');
      }
   }

And this is working. Maybe the other code used sqlite2 in a faulty way. I do not know. But finding this solution using sqlite3 in an object oriented way, I'm happy as it is. Now I can continue my project development.

This is where I found the solution: SQLite - PHP