<!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>Create blob, copy file in it, and close it</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ibase-blob-get.html">ibase_blob_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ibase-blob-info.html">ibase_blob_info</a></div> <div class="up"><a href="ref.ibase.html">Firebird/InterBase Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.ibase-blob-import" class="refentry"> <div class="refnamediv"> <h1 class="refname">ibase_blob_import</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">ibase_blob_import</span> — <span class="dc-title">Create blob, copy file in it, and close it</span></p> </div> <div class="refsect1 description" id="refsect1-function.ibase-blob-import-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>ibase_blob_import</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span> , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$file_handle</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>ibase_blob_import</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$file_handle</code></span> )</div> <p class="para rdfs-comment"> This function creates a BLOB, reads an entire file into it, closes it and returns the assigned BLOB id. </p> </div> <div class="refsect1 parameters" id="refsect1-function.ibase-blob-import-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">link_identifier</code></em></span> <dd> <p class="para"> An InterBase link identifier. If omitted, the last opened link is assumed. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">file_handle</code></em></span> <dd> <p class="para"> The file handle is a handle returned by <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.ibase-blob-import-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the BLOB id on success, or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 examples" id="refsect1-function.ibase-blob-import-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1105"> <p><strong>Example #1 <span class="function"><strong>ibase_blob_import()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$dbh </span><span style="color: #007700">= </span><span style="color: #0000BB">ibase_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$host</span><span style="color: #007700">, </span><span style="color: #0000BB">$username</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">'/tmp/bar'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$fd </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$fd</span><span style="color: #007700">) {<br /><br /> </span><span style="color: #0000BB">$blob </span><span style="color: #007700">= </span><span style="color: #0000BB">ibase_blob_import</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">, </span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /><br /> if (!</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$blob</span><span style="color: #007700">)) {<br /> </span><span style="color: #FF8000">// import failed<br /> </span><span style="color: #007700">} else {<br /> </span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"INSERT INTO foo (name, data) VALUES ('</span><span style="color: #0000BB">$filename</span><span style="color: #DD0000">', ?)"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$prepared </span><span style="color: #007700">= </span><span style="color: #0000BB">ibase_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">, </span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /> if (!</span><span style="color: #0000BB">ibase_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$prepared</span><span style="color: #007700">, </span><span style="color: #0000BB">$blob</span><span style="color: #007700">)) {<br /> </span><span style="color: #FF8000">// record insertion failed<br /> </span><span style="color: #007700">}<br /> }<br />} else {<br /> </span><span style="color: #FF8000">// unable to open the data file<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.ibase-blob-import-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.ibase-blob-add.html" class="function" rel="rdfs-seeAlso">ibase_blob_add()</a> - Add data into a newly created blob</span></li> <li class="member"> <span class="function"><a href="function.ibase-blob-cancel.html" class="function" rel="rdfs-seeAlso">ibase_blob_cancel()</a> - Cancel creating blob</span></li> <li class="member"> <span class="function"><a href="function.ibase-blob-close.html" class="function" rel="rdfs-seeAlso">ibase_blob_close()</a> - Close blob</span></li> <li class="member"> <span class="function"><a href="function.ibase-blob-create.html" class="function" rel="rdfs-seeAlso">ibase_blob_create()</a> - Create a new blob for adding data</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ibase-blob-get.html">ibase_blob_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ibase-blob-info.html">ibase_blob_info</a></div> <div class="up"><a href="ref.ibase.html">Firebird/InterBase Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>