Yun ,Sqlite, PHP and Python

I am new to this Unix / lineno thing.

Therefore, it took me some time to figure out how to access a sqlite database from php and python.

It turned out to be quite easy, so if there are others who are in the same situation, here's what I did:

PHP:

install install php5-mod-sqlite3

example php script to conect to sqlite database ec.db on the SD card

	db=new SQLite3("/mnt/sda1/arduino/www/test/ec.db");
     $results = $db->query('SELECT * FROM Navn');
     while ($row = $results->fetchArray()) {
     var_dump($row);
     print $row[1];
     }

Python:

Install python-sqlite3

Example python script

#!/usr/bin/python

import sqlite3 as lite
   import sys

con = None

try:
   con = lite.connect('test1.db')

 cur = con.cursor()
   cur.execute('SELECT * from test1')

 data = cur.fetchone()

 print data

except lite.Error, e:

 print "Error %s:" % e.args[0]
   sys.exit(1)

finally:

 if con:
   con.close()

More details:
http://www.ernstc.dk/arduino/Yun_start.htm

Thank you for sharing! Do you mind adding a reference to this topic on the playground page of the yun?

Hi,

I am also trying to install sqlite3 python module on Yun. I am using pip but it always gets stuck without installing :

root@ArduinoYunHomeWdli:~# pip install python-sqlite3
Downloading/unpacking python-sqlite3

Noting happens in the end and my ssh connection is disconnected after.
Any suggestion about how to get around the problem?

I figured this out:

On Yun, you 'd have to run opkg update first before opkg install. I think this might be because it can't save the repository list. Then run "opkg install python-sqlite3". That's all!

Hello @ all

php5 und sql works great but i have one problem to get the time in a php script on yun side

if i call

<?php echo Date(h,m,s); echo " "; ?>

i get the message

Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /mnt/sda1/arduino/www/Aqarium/time.php on line 4

i checked the funktion date_default_timezone_set()
but with no result :frowning:

what have i to do to get the actuall time

thanks

Maybe this will help

http://forum.arduino.cc/index.php?topic=190679.0

Thanks a lot,
thats it

I have yun shield, if I install using

opkg install php5-mod-sqlite3

It will install on internal memory. I have USB drive connected, how do I install directly on USB drive mounted on my yun shield's open wrt ?

seaurchin, I've never had a reason to try it so far (I assume it works), but I bookmarked this answer for when I had to do it:

http://forum.arduino.cc/index.php?topic=213019.msg2763430#new

seaurchin:
I have yun shield, if I install using

opkg install php5-mod-sqlite3

It will install on internal memory. I have USB drive connected, how do I install directly on USB drive mounted on my yun shield's open wrt ?

What you asked is Rootfs on External Storage/Expand the Storage, move root to External Storage:

http://www.ibuyopenwrt.com/index.php/administration

  • Expand the Storage
  • Expand the Storage II
  • Expand the Storage III