Jump to content

Using SQLite on Heliohost (via python)


plassma

Recommended Posts

Hello, first post here (yay!)

I have a possibly n00bish question: basically, how do you use SQlite on my site hosted on Stevie? I basically just have a simple form and I'd like new user input to it to be appended to a basic table in an SQLite database. I have the HTML form set up and communicating just fine with my python CGI, and the python CGI writes to the SQLite file fine when I test it on my home computer. However, I don't know where to direct the CGI to for writing to the SQLite db when running it on Heliohost. I've tried placing a preformatted SQLite db file in a few different places on the webpage to no avail. Is there a preferred location for the db file? OR is there a default location on the server tree which the db will save if I simply point the CGI script to the filename (without folders and subfolders, etc.) OR is there something I need to set up? Or is there just some problem with my code I'm missing...

 

Thanks in advance for any help.

Link to comment
Share on other sites

Is there a preferred location for the db file? OR is there a default location on the server tree which the db will save if I simply point the CGI script to the filename (without folders and subfolders, etc.)

 

It can go in the same directory as your form. I'm using sqlite with php and this is how I connect to my database.

 

<?php
$loadavg_array = explode(" ", file_get_contents("/proc/loadavg"));
$new_load = $loadavg_array[2];
$day = date("D");
$date = date("d");
$month = date("M");
$year = date("Y");
$time = time();

# open DB
$db = sqlite_open("load_db");

$sql = "INSERT INTO serverload
          (day, date, month, year, time, load)
        VALUES ('$day', $date, '$month', $year, $time, $new_load)";

# execute query
sqlite_query($db, "$sql");
?>

 

Link to comment
Share on other sites

Hmmm... thanks for the help but I'm still not getting it to run. Is there a preferred way to refer to the database on the server? Some how I'm just not getting data written to the file (though the exact same script works just within the confines of my own computer). Also, I'd prefer to save the database somewhere where it can't be accessed by the general public -- is this possible?

 

Is there a preferred location for the db file? OR is there a default location on the server tree which the db will save if I simply point the CGI script to the filename (without folders and subfolders, etc.)

 

It can go in the same directory as your form. I'm using sqlite with php and this is how I connect to my database.

 

<?php
$loadavg_array = explode(" ", file_get_contents("/proc/loadavg"));
$new_load = $loadavg_array[2];
$day = date("D");
$date = date("d");
$month = date("M");
$year = date("Y");
$time = time();

# open DB
$db = sqlite_open("load_db");

$sql = "INSERT INTO serverload
          (day, date, month, year, time, load)
        VALUES ('$day', $date, '$month', $year, $time, $new_load)";

# execute query
sqlite_query($db, "$sql");
?>

 

Link to comment
Share on other sites

Some how I'm just not getting data written to the file (though the exact same script works just within the confines of my own computer).

 

Have you created your database yet?

 

You could put your database inside your home directory where only you could see it. It would look something like this:

 

$db = sqlite_open("/home/byron/load_db");

 

 

Link to comment
Share on other sites

Yea I've already created and uploaded the database. I tried putting it in the home directory and pointing the script to it -- no real luck. There must be something odd I'm doing...

 

Some how I'm just not getting data written to the file (though the exact same script works just within the confines of my own computer).

 

Have you created your database yet?

 

You could put your database inside your home directory where only you could see it. It would look something like this:

 

$db = sqlite_open("/home/byron/load_db");

 

Link to comment
Share on other sites

Yeah it's probably something your just missing since the enviroment is different from you home computer. There's not a whole lot I can help you with when it comes to python. I would make sure that a simple python script was working on your site though.

 

 

Link to comment
Share on other sites

Ok, I found the problem -- not sure if you can help me solve it. My python script is running on python 2.4.6 by default, but my script requires 2.5+. The website says you guys have 2.7.1; do you know how to activate it or cause my CGI file to run through it?

 

Thanks so much for your help

 

Yeah it's probably something your just missing since the enviroment is different from you home computer. There's not a whole lot I can help you with when it comes to python. I would make sure that a simple python script was working on your site though.

 

 

Nevermind! Just had to specify in the python file! Thanks much, its all running now!

 

Ok, I found the problem -- not sure if you can help me solve it. My python script is running on python 2.4.6 by default, but my script requires 2.5+. The website says you guys have 2.7.1; do you know how to activate it or cause my CGI file to run through it?

 

Thanks so much for your help

 

Yeah it's probably something your just missing since the enviroment is different from you home computer. There's not a whole lot I can help you with when it comes to python. I would make sure that a simple python script was working on your site though.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...