LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2007, 03:59 PM   #1
gruessle
Member
 
Registered: Dec 2003
Location: USA
Distribution: Debian
Posts: 40

Rep: Reputation: 15
php and sqlite3 can select but not insert file is set rw


Hello,
I am trying to get started with sqlite3. Seams there is still
something wrong with my setup.
I am stuck and was wondering if someone could give me a hand.

I can select but it wont let me insert or update the database. The
error is "unable to open database file" however it does open the file
for a select query.

I think my code is fine because it works with a memory db. However I
will include the code below.
I also tried adding the 0666 to sqlite3_open but that does not work
either. My file is saved as rw for all.
sqlite3_open('db.sqlite', 0666) <= Does not work
-rw-rw-rw- 1 www-data www-data 2048 2007-01-25 02:31 db.sqlite

By the way I had to create the db.sqlite file from command line it
would not create it from php. So I also inserted some data from
command line. That is how I now that the select query works.

One more note, when I create the db in memory insert, update, create
table all works. But then when I commend out the create table line and
check my data it gives me the error that there is no table called
newuser in the db/memory.
Shouldn't that table be around for a little longer. I tried it with
not closing the db but it is still gone the second time I execute the
script. I am not planning on using a memory db so I could do with out
this. I just included this in case there is a relation.


Thank you

Dennis

=============

My test Code:

<?php

if ( ! $db = sqlite3_open("db.sqlite")) {
echo "Error db open: " . sqlite3_error($db);
}

$sqlCreateTable = 'CREATE TABLE newuser(id INTEGER PRIMARY KEY, email
CHAR(256), key CHAR(255))';
//$query = sqlite3_exec($db, $sqlCreateTable); // This only works in memory db


$query="INSERT INTO newuser (email,key) VALUES ('Tim','225')";
if (! $dbRes = sqlite3_exec($db, $query) ) {
echo "Error Insert: " . sqlite3_error($db);
} else {
echo "Changes: " . sqlite3_changes($db);
}

$query=sqlite3_query($db,"UPDATE newuser SET email = 'Tina' WHERE id = 1");
if (!$query) {
echo "Error query Update: " . sqlite3_error($db);
} else {
$query = sqlite3_query($db, "SELECT * from newuser");
$rows = array();
while ($r = sqlite3_fetch_array($query)) {
print_a($r);
}
}

sqlite3_query_close($query);
sqlite3_close($db);

?>
 
Old 01-25-2007, 11:59 PM   #2
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
Sqlite needs write permissions to the directory where the db file is.
 
Old 01-26-2007, 06:13 AM   #3
gruessle
Member
 
Registered: Dec 2003
Location: USA
Distribution: Debian
Posts: 40

Original Poster
Rep: Reputation: 15
Yes I found that out it needs to create a tmp db.

Thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sqlite3-3.2.1 execution error Aju Linux - Software 2 10-20-2005 10:17 AM
Insert problem Php petenyce Linux - Newbie 1 10-12-2005 03:52 PM
PHP insert. agallant Programming 4 08-17-2004 03:36 PM
problem with using STL set and its funciton erase , insert ashwinipahuja Programming 5 06-02-2004 01:29 AM
I need to insert and post PHP MYSQL DropHit Programming 2 02-19-2004 12:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration