SQLite Forum

Inserting the image as BLOB
Login
The same way you write an integer into an SQLite3 table.

```
a = 57;
db = sqlite3_open('database')
statement = db.prepare('insert into sometable (somecolumn) values (?)')
statement.bind_integer(1, a)
statement.execute()
```

except you want to load up the variable with the contents of the file.

```
a = file('image.jpg').read()
db = sqlite3_open('database')
statement = db.prepare('insert into sometable (somecolumn) values (?)')
statement.bind_blob(1, a)
statement.execute()
```

and to write it you do:

```
db = sqlite3_open('database')
statement = db.prepare('select somecolumn from sometable;')
statement.execute()
a = statement.column_blob(1)
open('image.jpg').write(a)
statement.close()
```

You will have to translate into PHP yourself.