<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="sqlite3.openblob" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>SQLite3::openBlob</refname>
  <refpurpose>Opens a stream resource to read a BLOB</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="SQLite3">
   <modifier>public</modifier> <type class="union"><type>resource</type><type>false</type></type><methodname>SQLite3::openBlob</methodname>
   <methodparam><type>string</type><parameter>table</parameter></methodparam>
   <methodparam><type>string</type><parameter>column</parameter></methodparam>
   <methodparam><type>int</type><parameter>rowid</parameter></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>database</parameter><initializer>"main"</initializer></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>SQLITE3_OPEN_READONLY</constant></initializer></methodparam>
  </methodsynopsis>
  <para>
   Opens a stream resource to read or write a BLOB, which would be selected by:
  </para>
  <para>
   SELECT <parameter>column</parameter> FROM <parameter>database</parameter>.<parameter>table</parameter> WHERE rowid = <parameter>rowid</parameter>
  </para>
  <note>
   <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.
   </simpara>
  </note>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>table</parameter></term>
     <listitem>
      <para>
       The table name.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>column</parameter></term>
     <listitem>
      <para>
       The column name.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>rowid</parameter></term>
     <listitem>
      <para>
       The row ID.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>database</parameter></term>
     <listitem>
      <para>
       The symbolic name of the DB
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>flags</parameter></term>
     <listitem>
      <para>
       Either <constant>SQLITE3_OPEN_READONLY</constant> or 
       <constant>SQLITE3_OPEN_READWRITE</constant> to open the stream
       for reading only, or for reading and writing, respectively.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>

 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a stream resource, &return.falseforfailure;.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>7.2.0</entry>
      <entry>
       The <parameter>flags</parameter> parameter has been added, allowing to
       write BLOBs; formerly only reading was supported.
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>SQLite3::openBlob</function> example</title>
    <programlisting role="php">
<![CDATA[
<?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();
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
Lorem ipsum
]]>
    </screen>
   </example>
  </para>
  <para>
   <example>
    <title>Incrementally writing a BLOB</title>
    <programlisting role="php">
<![CDATA[
<?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();
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
Lorem ipsum
Lorem ipsum
Lorem ipsum
]]>
    </screen>
   </example>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
