<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Opens a stream resource to read a BLOB</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.open.html">SQLite3::open</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.prepare.html">SQLite3::prepare</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sqlite3.openblob" class="refentry"> <div class="refnamediv"> <h1 class="refname">SQLite3::openBlob</h1> <p class="verinfo">(PHP 5 >= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">SQLite3::openBlob</span> — <span class="dc-title">Opens a stream resource to read a BLOB</span></p> </div> <div class="refsect1 description" id="refsect1-sqlite3.openblob-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">resource</span> <span class="methodname"><strong>SQLite3::openBlob</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$table</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$column</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$rowid</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$dbname</code><span class="initializer"> = "main"</span></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = SQLITE3_OPEN_READONLY</span></span> ]] )</div> <p class="para rdfs-comment"> Opens a stream resource to read or write a BLOB, which would be selected by: </p> <p class="para"> SELECT <code class="parameter">column</code> FROM <code class="parameter">dbname</code>.<code class="parameter">table</code> WHERE rowid = <code class="parameter">rowid</code> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> 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. </span> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-sqlite3.openblob-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">table</code></dt> <dd> <p class="para"> The table name. </p> </dd> <dt> <code class="parameter">column</code></dt> <dd> <p class="para"> The column name. </p> </dd> <dt> <code class="parameter">rowid</code></dt> <dd> <p class="para"> The row ID. </p> </dd> <dt> <code class="parameter">dbname</code></dt> <dd> <p class="para"> The symbolic name of the DB </p> </dd> <dt> <code class="parameter">flags</code></dt> <dd> <p class="para"> Either <strong><code>SQLITE3_OPEN_READONLY</code></strong> or <strong><code>SQLITE3_OPEN_READWRITE</code></strong> to open the stream for reading only, or for reading and writing, respectively. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-sqlite3.openblob-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a stream resource, or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 changelog" id="refsect1-sqlite3.openblob-changelog"> <h3 class="title">Changelog</h3> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>7.2.0</td> <td> The <code class="parameter">flags</code> parameter has been added, allowing to write BLOBs; formerly only reading was supported. </td> </tr> </tbody> </table> </div> <div class="refsect1 examples" id="refsect1-sqlite3.openblob-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2644"> <p><strong>Example #1 <span class="function"><strong>SQLite3::openBlob()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE TABLE test (text text)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES ('Lorem ipsum')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">openBlob</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">, </span><span style="color: #DD0000">'text'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">); </span><span style="color: #FF8000">// mandatory, otherwise the next line would fail<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Lorem ipsum </pre></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2645"> <p><strong>Example #2 Incrementally writing a BLOB</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE TABLE test (text text)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES (zeroblob(36))"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">openBlob</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">, </span><span style="color: #DD0000">'text'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'main'</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE3_OPEN_READWRITE</span><span style="color: #007700">);<br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">3</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #DD0000">"Lorem ipsum\n"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">querySingle</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT text FROM test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Lorem ipsum Lorem ipsum Lorem ipsum </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.open.html">SQLite3::open</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.prepare.html">SQLite3::prepare</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>