Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I would like to seek urgent help on just display what's in my database on plain html or php without any GUI interface or layout, just plain database display. Is it possible cause I'm new to it and keep struggling for a weeks already.

This is my python code:

import sqlite3
import RPi.GPIO as GPIO
import time
import datetime

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)

dbname='/var/www/ledDB.db'
now = datetime.datetime.now()
timestamp = now.strftime("%Y/%m/%d %H:%M")

pin7 = "INSERT INTO led values('" + "1" + "','" + "Red LED" + "','" + timestamp + "')"

def Blink(numTimes, speed):
    conn=sqlite3.connect(dbname)
    curs=conn.cursor()

    for i in range(numTimes):
        curs.execute(pin7)
        print "Iteration " + str(i + 1)
        GPIO.output(7, True)
        time.sleep(speed)
        GPIO.output(7, False)
        time.sleep(speed)
    print "Done"

    conn.commit()
    conn.close()
    GPIO.cleanup()

print "Blinking LED"

iterations = raw_input("Enter total number of times to blink: ")
speed = raw_input("Enter length of each blink(seconds): ")

Blink(int(iterations), float(speed))

Hope you guys could help me out with it as soon as possible, thanks in advance, guys.

share|improve this question

closed as off-topic by lenik, Milliways, Impulss, RPi Awesomeness, Bex Jul 17 '14 at 13:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, Milliways, Impulss, RPi Awesomeness, Bex
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
You need to get the data out of an sqlite database using Python right? Why are you pasting the database insertion code then? It has nothing to do with your question. –  João Pereira Jul 2 '14 at 10:59
    
Just want to show my code and maybe there are some area I should change so that's why I seeking for help from you guys, Hal –  user3127380 Jul 2 '14 at 11:53
    
Please accept the answer if you feel your question has been answered correctly –  João Pereira Jul 3 '14 at 10:49
    
@user3127380 This would fit better on Code Review, a site meant for code review or Stack Overflow, a programming-specific Stack Exchange. This site is specifically meant for Raspberry Pi-related issues (GPIO, PiCam, issues that occur only on the Pi - not on a PC, etc...) –  RPi Awesomeness Jul 4 '14 at 14:51

1 Answer 1

up vote 2 down vote accepted

Here's a sample script to read an sqlite3 database using Python:

import sqlite3 conn = sqlite3.connect('example.db')

c = conn.cursor()

for row in c.execute('SELECT * FROM led'): print row

Check out the documentation, it's pretty good.

share|improve this answer
    
Thanks alot, Hal. It works. –  user3127380 Jul 3 '14 at 12:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.