Jump to content

Uploading files to sqlite2


Recommended Posts

Hi,

 

I try to insert an image into a sqlite2 table, but every time i get this error message:

Warning: sqlite_exec() [function.sqlite-exec]: unrecognized token: "#" in \var\www\localhost\htdocs\upload\index.php on line 4

Error in query: 'unrecognized token: "#"'

 

Here is the code:

$fileContent=file_get_contents($_FILES['image']['tmp_name'],FILE_TEXT);
$fileContent=sqlite_escape_string($fileContent);
$dbhandle = sqlite_open('image.sqlite');
$query = sqlite_exec($dbhandle, 'INSERT INTO image VALUES ("'.$_FILES['image']['type'].'","'.$fileContent.'")', $error);
if (!$query) {
    exit("Error in query: '$error'");
} else {
    echo 'Number of rows modified: ', sqlite_changes($dbhandle);
}

 

My interim solution at the moment is that I convert each char to ASCII, but that takes about 3-times more space in the db.

Link to comment
https://forums.phpfreaks.com/topic/167120-uploading-files-to-sqlite2/
Share on other sites

I'm not an sqlite expert, but I've got to question the decision to store blobs in an embedded database. You'd be better off storing the file in the file system and storing the link to it in the db.

 

That said, if you want to store a blob, you'll need to use the right tools

http://www.sqlite.org/c3ref/blob.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.