-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathlobcreate.xml
116 lines (110 loc) · 3.62 KB
/
lobcreate.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="pdo-pgsql.lobcreate" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Pdo\Pgsql::lobCreate</refname>
<refpurpose>Creates a new large object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="Pdo\\Pgsql">
<modifier>public</modifier> <type class="union"><type>string</type><type>false</type></type><methodname>Pdo\Pgsql::lobCreate</methodname>
<void/>
</methodsynopsis>
<simpara>
<methodname>Pdo\Pgsql::lobCreate</methodname> creates a large object
and returns the OID which refers to it.
It can be opened to read or write data with
<methodname>Pdo\Pgsql::lobOpen</methodname>.
</simpara>
<simpara>
The OID can be stored in columns of type OID and be used to reference
the large object, without causing the row to grow arbitrarily large.
The large object will continue to live in the database until it
is removed by calling <methodname>Pdo\Pgsql::lobUnlink</methodname>.
</simpara>
<simpara>
Large objects are cumbersome to use.
Indeed, it is required that <methodname>Pdo\Pgsql::lobUnlink</methodname>
is called prior to deleting the last row referencing the OID in the entire database;
otherwise, unreferenced large objects will remain on the server indefinitely.
Moreover, large objects have no access controls.
An alternative is the bytea column type, which can be up to 1GB in size,
and this column type transparently manages the storage for optimal row size.
</simpara>
<note>
<simpara>
This function, and all manipulations of the large object,
must be called and carried out within a transaction.
</simpara>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
Returns the OID of the newly created large object on success,
&return.falseforfailure;.
</simpara>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="pdo-pgsql.lobcreate.example.basic">
<title><methodname>Pdo\Pgsql::lobCreate</methodname> example</title>
<simpara>
This example creates a new large object and copies the contents
of a file into it.
The OID is then stored into a table.
</simpara>
<programlisting role="php">
<![CDATA[
<?php
$db = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->beginTransaction();
$oid = $db->lobCreate();
$stream = $db->lobOpen($oid, 'w');
$local = fopen($filename, 'rb');
stream_copy_to_stream($local, $stream);
$local = null;
$stream = null;
$stmt = $db->prepare("INSERT INTO BLOBS (ident, oid) VALUES (?, ?)");
$stmt->execute([$some_id, $oid]);
$db->commit();
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>Pdo\Pgsql::lobOpen</methodname></member>
<member><methodname>Pdo\Pgsql::lobUnlink</methodname></member>
<member><function>pg_lo_create</function></member>
<member><function>pg_lo_open</function></member>
</simplelist>
</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
-->