Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.