Go Down

Topic: Yún, PHP and SQLite (Read 841 times) previous topic - next topic


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:
Code: [Select]
echo sqlite_libversion();

I got version number 2.8.17
But this one result in <h1>Bad Gateway</h1>The process did not produce any response
Code: [Select]
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 {

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:

Code: [Select]
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 + ");")
    print k + " : " + t
    print "INSERT INTO tblTempHist VALUES('" + k + "'," + t + ");"
s.enter(1, 1, do_something, (s,))


Hi again

I found some other samplecode starting like this:

Code: [Select]
class MyDB extends SQLite3

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: http://www.tutorialspoint.com/sqlite/sqlite_php.htm

Go Up