reference/pgsql/functions/pg-update.xml
c2eca73ef79ebe78cebb34053e41b565af504c4f
...
...
@@ -1,7 +1,7 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
3
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.80 -->
4
-
<refentry xml:id='function.pg-update' xmlns="http://docbook.org/ns/docbook">
4
+
<refentry xml:id="function.pg-update" xmlns="http://docbook.org/ns/docbook">
5
5
<refnamediv>
6
6
<refname>pg_update</refname>
7
7
<refpurpose>
...
...
@@ -12,21 +12,34 @@
12
12
<refsect1 role="description">
13
13
&reftitle.description;
14
14
<methodsynopsis>
15
-
<type>mixed</type><methodname>pg_update</methodname>
16
-
<methodparam><type>resource</type><parameter>connection</parameter></methodparam>
15
+
<type class="union"><type>string</type><type>bool</type></type><methodname>pg_update</methodname>
16
+
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
17
17
<methodparam><type>string</type><parameter>table_name</parameter></methodparam>
18
-
<methodparam><type>array</type><parameter>data</parameter></methodparam>
19
-
<methodparam><type>array</type><parameter>condition</parameter></methodparam>
20
-
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>PGSQL_DML_EXEC</initializer></methodparam>
18
+
<methodparam><type>array</type><parameter>values</parameter></methodparam>
19
+
<methodparam><type>array</type><parameter>conditions</parameter></methodparam>
20
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PGSQL_DML_EXEC</constant></initializer></methodparam>
21
21
</methodsynopsis>
22
22
<para>
23
23
<function>pg_update</function> updates records that matches
24
-
<literal>condition</literal> with <literal>data</literal>. If
25
-
<literal>options</literal> is specified,
24
+
<parameter>conditions</parameter> with <parameter>values</parameter>.
25
+
</para>
26
+
<para>
27
+
If <parameter>flags</parameter> is specified,
26
28
<function>pg_convert</function> is applied to
27
-
<literal>data</literal> with specified options.
29
+
<parameter>values</parameter> with the specified flags.
30
+
</para>
31
+
<para>
32
+
By default <function>pg_update</function> passes raw values.
33
+
Values must be escaped or the <constant>PGSQL_DML_ESCAPE</constant> flag
34
+
must be specified in <parameter>flags</parameter>.
35
+
<constant>PGSQL_DML_ESCAPE</constant> quotes and escapes parameters/identifiers.
36
+
Therefore, table/column names become case sensitive.
37
+
</para>
38
+
<para>
39
+
Note that neither escape nor prepared query can protect LIKE query,
40
+
JSON, Array, Regex, etc. These parameters should be handled
41
+
according to their contexts. i.e. Escape/validate values.
28
42
</para>
29
-
&warn.experimental.func;
30
43
</refsect1>
31
44

32
45
<refsect1 role="parameters">
...
...
@@ -36,9 +49,7 @@
36
49
<varlistentry>
37
50
<term><parameter>connection</parameter></term>
38
51
<listitem>
39
-
<para>
40
-
PostgreSQL database connection resource.
41
-
</para>
52
+
&pgsql.parameter.connection;
42
53
</listitem>
43
54
</varlistentry>
44
55
<varlistentry>
...
...
@@ -50,7 +61,7 @@
50
61
</listitem>
51
62
</varlistentry>
52
63
<varlistentry>
53
-
<term><parameter>data</parameter></term>
64
+
<term><parameter>values</parameter></term>
54
65
<listitem>
55
66
<para>
56
67
An <type>array</type> whose keys are field names in the table <parameter>table_name</parameter>,
...
...
@@ -59,7 +70,7 @@
59
70
</listitem>
60
71
</varlistentry>
61
72
<varlistentry>
62
-
<term><parameter>condition</parameter></term>
73
+
<term><parameter>conditions</parameter></term>
63
74
<listitem>
64
75
<para>
65
76
An <type>array</type> whose keys are field names in the table <parameter>table_name</parameter>,
...
...
@@ -68,14 +79,17 @@
68
79
</listitem>
69
80
</varlistentry>
70
81
<varlistentry>
71
-
<term><parameter>options</parameter></term>
82
+
<term><parameter>flags</parameter></term>
72
83
<listitem>
73
84
<para>
74
-
Any number of <constant>PGSQL_CONV_OPTS</constant>,
85
+
Any number of <constant>PGSQL_CONV_FORCE_NULL</constant>,
75
86
<constant>PGSQL_DML_NO_CONV</constant>,
76
-
<constant>PGSQL_DML_EXEC</constant> or
87
+
<constant>PGSQL_DML_ESCAPE</constant>,
88
+
<constant>PGSQL_DML_EXEC</constant>,
89
+
<constant>PGSQL_DML_ASYNC</constant> or
77
90
<constant>PGSQL_DML_STRING</constant> combined. If <constant>PGSQL_DML_STRING</constant> is part of the
78
-
<parameter>options</parameter> then query string is returned.
91
+
<parameter>flags</parameter> then query string is returned. When <constant>PGSQL_DML_NO_CONV</constant>
92
+
or <constant>PGSQL_DML_ESCAPE</constant> is set, it does not call <function>pg_convert</function> internally.
79
93
</para>
80
94
</listitem>
81
95
</varlistentry>
...
...
@@ -87,10 +101,27 @@
87
101
&reftitle.returnvalues;
88
102
<para>
89
103
&return.success; Returns <type>string</type> if <constant>PGSQL_DML_STRING</constant> is passed
90
-
via <parameter>options</parameter>.
104
+
via <parameter>flags</parameter>.
91
105
</para>
92
106
</refsect1>
93
107

108
+
<refsect1 role="changelog">
109
+
&reftitle.changelog;
110
+
<informaltable>
111
+
<tgroup cols="2">
112
+
<thead>
113
+
<row>
114
+
<entry>&Version;</entry>
115
+
<entry>&Description;</entry>
116
+
</row>
117
+
</thead>
118
+
<tbody>
119
+
&pgsql.changelog.connection-object;
120
+
</tbody>
121
+
</tgroup>
122
+
</informaltable>
123
+
</refsect1>
124
+
94
125
<refsect1 role="examples">
95
126
&reftitle.examples;
96
127
<para>
...
...
@@ -101,8 +132,9 @@
101
132
<?php
102
133
$db = pg_connect('dbname=foo');
103
134
$data = array('field1'=>'AA', 'field2'=>'BB');
104
-
105
-
// This is safe, since $_POST is converted automatically
135
+
// This is safe somewhat, since all values are escaped.
136
+
// However PostgreSQL supports JSON/Array. These are not
137
+
// safe by neither escape nor prepared query.
106
138
$res = pg_update($db, 'post_log', $_POST, $data);
107
139
if ($res) {
108
140
echo "Data is updated: $res\n";
...
...
@@ -125,7 +157,6 @@
125
157
</para>
126
158
</refsect1>
127
159
</refentry>
128
-

129
160
<!-- Keep this comment at the end of the file
130
161
Local variables:
131
162
mode: sgml
132
163