Author Topic: SQLite Query Error: "unable to open database file".  (Read 14800 times)

0 Members and 2 Guests are viewing this topic.

Offline DewdTopic starter

  • Irregular
  • Posts: 1
    • View Profile
SQLite Query Error: "unable to open database file".
« on: October 03, 2008, 05:47:08 PM »
Hello,

I have a bit of a problem with a simple message board using a SQLite database.

When my script queries:

Code: [Select]
SELECT * FROM posts ORDER BY id ASC
It works absolutely fine.

When I try to:

Code: [Select]
sqlite_query($handle, "INSERT INTO posts (name, post, date) VALUES ('" . $message_name . "', '" . $message_msg . "', '" . $message_date . "')") or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
It gives me a error saying:

Code: [Select]
Warning: sqlite_query() [function.sqlite-query]: unable to open database file in *script location* on line 24
Error in query: unable to open database file.

The whole condition is:

if (isset($_POST['name']) && isset($_POST['msg'])) {
	
$message_name $_POST['name'];
	
$message_msg $_POST['msg'];
	
$message_date date("d/m/y");
	

	
sqlite_query($handle"INSERT INTO posts (name, post, date) VALUES ('" $message_name "', '" $message_msg "', '" $message_date "')") or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
	

	
echo 
'<b>Your post was successful!</b><br/>' ;
}


Is there something wrong? Am I using the strings wrongly? Is there a error in the query?

Thanks for any help.

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: SQLite Query Error: "unable to open database file".
« Reply #1 on: October 03, 2008, 09:35:31 PM »
Since the query is generating an error about opening the file, best guess is that there is no valid/error-free sqlite_open() statement prior to the query.

It would really take seeing all the relevant code for anyone one to be able to see what might be causing the problem or to be able to duplicate it on their own system.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline chefsalat

  • Irregular
  • Posts: 1
    • View Profile
Re: SQLite Query Error: "unable to open database file".
« Reply #2 on: December 12, 2009, 08:57:21 AM »
Hello Dewd,

i Had the same problem on my linux-System. My databases are in the directory "sqlite". The databases had the "0777" permissions. But the directory "sqlite" himself had the "0755" permissions.

A "chmod 0777 sqlite" had solved the problem.
I hope, it solves your problem too.