<!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 a large object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-lo-close.html">pg_lo_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-lo-export.html">pg_lo_export</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.pg-lo-create" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_lo_create</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_lo_create</span> — <span class="dc-title">Create a large object</span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-lo-create-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>pg_lo_create</strong></span> ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$object_id</code></span> ]] )</div> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>pg_lo_create</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$object_id</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_lo_create()</strong></span> creates a large object and returns the <var class="varname"><var class="varname">OID</var></var> of the large object. PostgreSQL access modes <strong><code>INV_READ</code></strong>, <strong><code>INV_WRITE</code></strong>, and <strong><code>INV_ARCHIVE</code></strong> are not supported, the object is created always with both read and write access. <strong><code>INV_ARCHIVE</code></strong> has been removed from PostgreSQL itself (version 6.3 and above). </p> <p class="para"> To use the large object interface, it is necessary to enclose it within a transaction block. </p> <p class="para"> Instead of using the large object interface (which has no access controls and is cumbersome to use), try PostgreSQL's <var class="varname"><var class="varname">bytea</var></var> column type and <span class="function"><a href="function.pg-escape-bytea.html" class="function">pg_escape_bytea()</a></span>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This function used to be called <span class="function"><strong>pg_locreate()</strong></span>. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.pg-lo-create-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">connection</code></em></span> <dd> <p class="para"> PostgreSQL database connection resource. When <em><code class="parameter">connection</code></em> is not present, the default connection is used. The default connection is the last connection made by <span class="function"><a href="function.pg-connect.html" class="function">pg_connect()</a></span> or <span class="function"><a href="function.pg-pconnect.html" class="function">pg_pconnect()</a></span>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">object_id</code></em></span> <dd> <p class="para"> If an <em><code class="parameter">object_id</code></em> is given the function will try to create a large object with this id, else a free object id is assigned by the server. The parameter was added in PHP 5.3 and relies on functionality that first appeared in PostgreSQL 8.1. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-lo-create-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> A large object <var class="varname"><var class="varname">OID</var></var> or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 changelog" id="refsect1-function.pg-lo-create-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.3.0</td> <td><p class="para"> The optional <em><code class="parameter">object_id</code></em> was added. </p></td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-lo-create-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2089"> <p><strong>Example #1 <span class="function"><strong>pg_lo_create()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $database </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=jacarta"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #DD0000">"begin"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$oid </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_lo_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$oid</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$handle </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_lo_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$oid</span><span style="color: #007700">, </span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$handle</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">pg_lo_write</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">, </span><span style="color: #DD0000">"large object data"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">pg_lo_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #DD0000">"commit"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></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="function.pg-lo-close.html">pg_lo_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-lo-export.html">pg_lo_export</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>