📄 function.pdo-pgsqllobopen.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Opens an existing large object stream</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pdo-pgsqllobcreate.html">PDO::pgsqlLOBCreate</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pdo-pgsqllobunlink.html">PDO::pgsqlLOBUnlink</a></div> <div class="up"><a href="ref.pdo-pgsql.html">PostgreSQL (PDO)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.pdo-pgsqllobopen" class="refentry"> <div class="refnamediv"> <h1 class="refname">PDO::pgsqlLOBOpen</h1> <p class="verinfo">(PHP 5 >= 5.1.2, PECL pdo_pgsql:1.0.1-1.0.2)</p><p class="refpurpose"><span class="refname">PDO::pgsqlLOBOpen</span> — <span class="dc-title">Opens an existing large object stream</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>PDO::pgsqlLOBOpen</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$oid</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$mode</tt></span> ] )</div> <p class="para rdfs-comment"> <b>PDO::pgsqlLOBOpen()</b> opens a stream to access the data referenced by <i><tt class="parameter">oid</tt></i>. If <i><tt class="parameter">mode</tt></i> is <i>r</i>, the stream is opened for reading, if <i><tt class="parameter">mode</tt></i> is <i>w</i>, then the stream will be opened for writing. You can use all the usual filesystem functions, such as <a href="function.fread.html" class="function">fread()</a>, <a href="function.fwrite.html" class="function">fwrite()</a> and <a href="function.fgets.html" class="function">fgets()</a> to manipulate the contents of the stream. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara"> This function, and all manipulations of the large object, must be called and carried out within a transaction. </span> </p></blockquote></div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">oid</tt></i></span> <dd> <p class="para"> A large object identifier. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">mode</tt></i></span> <dd> <p class="para"> If mode is <i>r</i>, open the stream for reading. If mode is <i>w</i>, open the stream for writing. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a stream resource on success, or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 A <b>PDO::pgsqlLOBOpen()</b> example</b></p> <div class="example-contents"><p> Following on from the <a href="function.pdo-pgsqllobcreate.html" class="function">PDO::pgsqlLOBCreate()</a> example, this code snippet retrieves the large object from the database and outputs it to the browser. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'pgsql:dbname=test host=localhost'</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">setAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_ERRMODE</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ERRMODE_EXCEPTION</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">beginTransaction</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"select oid from BLOBS where ident = ?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$some_id</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">bindColumn</span><span style="color: #007700">(</span><span style="color: #DD0000">'oid'</span><span style="color: #007700">, </span><span style="color: #0000BB">$lob</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_LOB</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_BOUND</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$lob</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.pdo-pgsqllobcreate.html" class="function" rel="rdfs-seeAlso">PDO::pgsqlLOBCreate()</a></li> <li class="member"><a href="function.pdo-pgsqllobunlink.html" class="function" rel="rdfs-seeAlso">PDO::pgsqlLOBUnlink()</a></li> <li class="member"><a href="function.pg-lo-open.html" class="function" rel="rdfs-seeAlso">pg_lo_open()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pdo-pgsqllobcreate.html">PDO::pgsqlLOBCreate</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pdo-pgsqllobunlink.html">PDO::pgsqlLOBUnlink</a></div> <div class="up"><a href="ref.pdo-pgsql.html">PostgreSQL (PDO)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -