SQLite3::openBlob
(PHP 5 >= 5.3.0, PHP 7)
SQLite3::openBlob — Opens a stream resource to read a BLOB
Description
$table
, string $column
, int $rowid
[, string $dbname
= "main"
[, int $flags
= SQLITE3_OPEN_READONLY
]] ) : resourceOpens a stream resource to read or write a BLOB, which would be selected by:
SELECT column
FROM dbname
.table
WHERE rowid = rowid
Note: It is not possible to change the size of a BLOB by writing to the stream. Instead, an UPDATE statement has to be executed, possibly using SQLite's zeroblob() function to set the desired BLOB size.
Parameters
-
table
-
The table name.
-
column
-
The column name.
-
rowid
-
The row ID.
-
dbname
-
The symbolic name of the DB
-
flags
-
Either
SQLITE3_OPEN_READONLY
orSQLITE3_OPEN_READWRITE
to open the stream for reading only, or for reading and writing, respectively.
Changelog
Version | Description |
---|---|
7.2.0 |
The flags parameter has been added, allowing to
write BLOBs; formerly only reading was supported.
|
Examples
Example #1 SQLite3::openBlob() example
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES ('Lorem ipsum')");
$stream = $conn->openBlob('test', 'text', 1);
echo stream_get_contents($stream);
fclose($stream); // mandatory, otherwise the next line would fail
$conn->close();
?>
The above example will output:
Lorem ipsum
Example #2 Incrementally writing a BLOB
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES (zeroblob(36))");
$stream = $conn->openBlob('test', 'text', 1, 'main', SQLITE3_OPEN_READWRITE);
for ($i = 0; $i < 3; $i++) {
fwrite($stream, "Lorem ipsum\n");
}
fclose($stream);
echo $conn->querySingle("SELECT text FROM test");
$conn->close();
?>
The above example will output:
Lorem ipsum Lorem ipsum Lorem ipsum
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-sqlite3.openblob.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.