PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / third-party / vendor / thecodingmachine / safe / generated / pgsql.php
wp-user-avatar / third-party / vendor / thecodingmachine / safe / generated Last commit date
Exceptions 5 days ago apache.php 5 days ago apcu.php 5 days ago array.php 5 days ago bzip2.php 5 days ago calendar.php 5 days ago classobj.php 5 days ago com.php 5 days ago cubrid.php 5 days ago curl.php 5 days ago datetime.php 5 days ago dir.php 5 days ago eio.php 5 days ago errorfunc.php 5 days ago exec.php 5 days ago fileinfo.php 5 days ago filesystem.php 5 days ago filter.php 5 days ago fpm.php 5 days ago ftp.php 5 days ago funchand.php 5 days ago functionsList.php 5 days ago gmp.php 5 days ago gnupg.php 5 days ago hash.php 5 days ago ibase.php 5 days ago ibmDb2.php 5 days ago iconv.php 5 days ago image.php 5 days ago imap.php 5 days ago info.php 5 days ago ingres-ii.php 5 days ago inotify.php 5 days ago json.php 5 days ago ldap.php 5 days ago libxml.php 5 days ago lzf.php 5 days ago mailparse.php 5 days ago mbstring.php 5 days ago misc.php 5 days ago msql.php 5 days ago mysql.php 5 days ago mysqli.php 5 days ago mysqlndMs.php 5 days ago mysqlndQc.php 5 days ago network.php 5 days ago oci8.php 5 days ago opcache.php 5 days ago openssl.php 5 days ago outcontrol.php 5 days ago password.php 5 days ago pcntl.php 5 days ago pcre.php 5 days ago pdf.php 5 days ago pgsql.php 5 days ago posix.php 5 days ago ps.php 5 days ago pspell.php 5 days ago readline.php 5 days ago rpminfo.php 5 days ago rrd.php 5 days ago sem.php 5 days ago session.php 5 days ago shmop.php 5 days ago simplexml.php 5 days ago sockets.php 5 days ago sodium.php 5 days ago solr.php 5 days ago spl.php 5 days ago sqlsrv.php 5 days ago ssdeep.php 5 days ago ssh2.php 5 days ago stream.php 5 days ago strings.php 5 days ago swoole.php 5 days ago uodbc.php 5 days ago uopz.php 5 days ago url.php 5 days ago var.php 5 days ago xdiff.php 5 days ago xml.php 5 days ago xmlrpc.php 5 days ago yaml.php 5 days ago yaz.php 5 days ago zip.php 5 days ago zlib.php 5 days ago
pgsql.php
1772 lines
1 <?php
2
3 namespace ProfilePressVendor\Safe;
4
5 use ProfilePressVendor\Safe\Exceptions\PgsqlException;
6 /**
7 * pg_cancel_query cancels an asynchronous query sent with
8 * pg_send_query, pg_send_query_params
9 * or pg_send_execute. You cannot cancel a query executed using
10 * pg_query.
11 *
12 * @param resource $connection PostgreSQL database connection resource.
13 * @throws PgsqlException
14 *
15 */
16 function pg_cancel_query($connection): void
17 {
18 error_clear_last();
19 $result = \pg_cancel_query($connection);
20 if ($result === \false) {
21 throw PgsqlException::createFromPhpError();
22 }
23 }
24 /**
25 * PostgreSQL supports automatic character set conversion between
26 * server and client for certain character sets.
27 * pg_client_encoding returns the client
28 * encoding as a string. The returned string will be one of the
29 * standard PostgreSQL encoding identifiers.
30 *
31 * @param resource $connection PostgreSQL database connection resource. When
32 * connection is not present, the default connection
33 * is used. The default connection is the last connection made by
34 * pg_connect or pg_pconnect.
35 * @return string The client encoding.
36 * @throws PgsqlException
37 *
38 */
39 function pg_client_encoding($connection = null): string
40 {
41 error_clear_last();
42 if ($connection !== null) {
43 $result = \pg_client_encoding($connection);
44 } else {
45 $result = \pg_client_encoding();
46 }
47 if ($result === \false) {
48 throw PgsqlException::createFromPhpError();
49 }
50 return $result;
51 }
52 /**
53 * pg_close closes the non-persistent
54 * connection to a PostgreSQL database associated with the given
55 * connection resource.
56 *
57 * If there is open large object resource on the connection, do not
58 * close the connection before closing all large object resources.
59 *
60 * @param resource $connection PostgreSQL database connection resource. When
61 * connection is not present, the default connection
62 * is used. The default connection is the last connection made by
63 * pg_connect or pg_pconnect.
64 * @throws PgsqlException
65 *
66 */
67 function pg_close($connection = null): void
68 {
69 error_clear_last();
70 if ($connection !== null) {
71 $result = \pg_close($connection);
72 } else {
73 $result = \pg_close();
74 }
75 if ($result === \false) {
76 throw PgsqlException::createFromPhpError();
77 }
78 }
79 /**
80 * pg_connect opens a connection to a
81 * PostgreSQL database specified by the
82 * connection_string.
83 *
84 * If a second call is made to pg_connect with
85 * the same connection_string as an existing connection, the
86 * existing connection will be returned unless you pass
87 * PGSQL_CONNECT_FORCE_NEW as
88 * connect_type.
89 *
90 * The old syntax with multiple parameters
91 * $conn = pg_connect("host", "port", "options", "tty", "dbname")
92 * has been deprecated.
93 *
94 * @param string $connection_string The connection_string can be empty to use all default parameters, or it
95 * can contain one or more parameter settings separated by whitespace.
96 * Each parameter setting is in the form keyword = value. Spaces around
97 * the equal sign are optional. To write an empty value or a value
98 * containing spaces, surround it with single quotes, e.g., keyword =
99 * 'a value'. Single quotes and backslashes within the value must be
100 * escaped with a backslash, i.e., \' and \\.
101 *
102 * The currently recognized parameter keywords are:
103 * host, hostaddr, port,
104 * dbname (defaults to value of user),
105 * user,
106 * password, connect_timeout,
107 * options, tty (ignored), sslmode,
108 * requiressl (deprecated in favor of sslmode), and
109 * service. Which of these arguments exist depends
110 * on your PostgreSQL version.
111 *
112 * The options parameter can be used to set command line parameters
113 * to be invoked by the server.
114 * @param int $connect_type If PGSQL_CONNECT_FORCE_NEW is passed, then a new connection
115 * is created, even if the connection_string is identical to
116 * an existing connection.
117 *
118 * If PGSQL_CONNECT_ASYNC is given, then the
119 * connection is established asynchronously. The state of the connection
120 * can then be checked via pg_connect_poll or
121 * pg_connection_status.
122 * @return resource PostgreSQL connection resource on success, FALSE on failure.
123 * @throws PgsqlException
124 *
125 */
126 function pg_connect(string $connection_string, int $connect_type = null)
127 {
128 error_clear_last();
129 if ($connect_type !== null) {
130 $result = \pg_connect($connection_string, $connect_type);
131 } else {
132 $result = \pg_connect($connection_string);
133 }
134 if ($result === \false) {
135 throw PgsqlException::createFromPhpError();
136 }
137 return $result;
138 }
139 /**
140 * pg_connection_reset resets the connection.
141 * It is useful for error recovery.
142 *
143 * @param resource $connection PostgreSQL database connection resource.
144 * @throws PgsqlException
145 *
146 */
147 function pg_connection_reset($connection): void
148 {
149 error_clear_last();
150 $result = \pg_connection_reset($connection);
151 if ($result === \false) {
152 throw PgsqlException::createFromPhpError();
153 }
154 }
155 /**
156 * pg_convert checks and converts the values in
157 * assoc_array into suitable values for use in an SQL
158 * statement. Precondition for pg_convert is the
159 * existence of a table table_name which has at least
160 * as many columns as assoc_array has elements. The
161 * fieldnames in table_name must match the indices in
162 * assoc_array and the corresponding datatypes must be
163 * compatible. Returns an array with the converted values on success, FALSE
164 * otherwise.
165 *
166 * @param resource $connection PostgreSQL database connection resource.
167 * @param string $table_name Name of the table against which to convert types.
168 * @param array $assoc_array Data to be converted.
169 * @param int $options Any number of PGSQL_CONV_IGNORE_DEFAULT,
170 * PGSQL_CONV_FORCE_NULL or
171 * PGSQL_CONV_IGNORE_NOT_NULL, combined.
172 * @return array An array of converted values.
173 * @throws PgsqlException
174 *
175 */
176 function pg_convert($connection, string $table_name, array $assoc_array, int $options = 0): array
177 {
178 error_clear_last();
179 $result = \pg_convert($connection, $table_name, $assoc_array, $options);
180 if ($result === \false) {
181 throw PgsqlException::createFromPhpError();
182 }
183 return $result;
184 }
185 /**
186 * pg_copy_from inserts records into a table from
187 * rows. It issues a COPY FROM SQL command
188 * internally to insert records.
189 *
190 * @param resource $connection PostgreSQL database connection resource.
191 * @param string $table_name Name of the table into which to copy the rows.
192 * @param array $rows An array of data to be copied into table_name.
193 * Each value in rows becomes a row in table_name.
194 * Each value in rows should be a delimited string of the values
195 * to insert into each field. Values should be linefeed terminated.
196 * @param string $delimiter The token that separates values for each field in each element of
197 * rows. Default is TAB.
198 * @param string $null_as How SQL NULL values are represented in the
199 * rows. Default is \N ("\\N").
200 * @throws PgsqlException
201 *
202 */
203 function pg_copy_from($connection, string $table_name, array $rows, string $delimiter = null, string $null_as = null): void
204 {
205 error_clear_last();
206 if ($null_as !== null) {
207 $result = \pg_copy_from($connection, $table_name, $rows, $delimiter, $null_as);
208 } elseif ($delimiter !== null) {
209 $result = \pg_copy_from($connection, $table_name, $rows, $delimiter);
210 } else {
211 $result = \pg_copy_from($connection, $table_name, $rows);
212 }
213 if ($result === \false) {
214 throw PgsqlException::createFromPhpError();
215 }
216 }
217 /**
218 * pg_copy_to copies a table to an array. It
219 * issues COPY TO SQL command internally to
220 * retrieve records.
221 *
222 * @param resource $connection PostgreSQL database connection resource.
223 * @param string $table_name Name of the table from which to copy the data into rows.
224 * @param string $delimiter The token that separates values for each field in each element of
225 * rows. Default is TAB.
226 * @param string $null_as How SQL NULL values are represented in the
227 * rows. Default is \N ("\\N").
228 * @return array An array with one element for each line of COPY data.
229 * It returns FALSE on failure.
230 * @throws PgsqlException
231 *
232 */
233 function pg_copy_to($connection, string $table_name, string $delimiter = null, string $null_as = null): array
234 {
235 error_clear_last();
236 if ($null_as !== null) {
237 $result = \pg_copy_to($connection, $table_name, $delimiter, $null_as);
238 } elseif ($delimiter !== null) {
239 $result = \pg_copy_to($connection, $table_name, $delimiter);
240 } else {
241 $result = \pg_copy_to($connection, $table_name);
242 }
243 if ($result === \false) {
244 throw PgsqlException::createFromPhpError();
245 }
246 return $result;
247 }
248 /**
249 * pg_dbname returns the name of the database
250 * that the given PostgreSQL connection
251 * resource.
252 *
253 * @param resource $connection PostgreSQL database connection resource. When
254 * connection is not present, the default connection
255 * is used. The default connection is the last connection made by
256 * pg_connect or pg_pconnect.
257 * @return string A string containing the name of the database the
258 * connection is to.
259 * @throws PgsqlException
260 *
261 */
262 function pg_dbname($connection = null): string
263 {
264 error_clear_last();
265 if ($connection !== null) {
266 $result = \pg_dbname($connection);
267 } else {
268 $result = \pg_dbname();
269 }
270 if ($result === \false) {
271 throw PgsqlException::createFromPhpError();
272 }
273 return $result;
274 }
275 /**
276 * pg_delete deletes records from a table
277 * specified by the keys and values
278 * in assoc_array. If options
279 * is specified, pg_convert is applied
280 * to assoc_array with the specified options.
281 *
282 * If options is specified,
283 * pg_convert is applied to
284 * assoc_array with the specified flags.
285 *
286 * By default pg_delete passes raw values. Values
287 * must be escaped or PGSQL_DML_ESCAPE option must be
288 * specified. PGSQL_DML_ESCAPE quotes and escapes
289 * parameters/identifiers. Therefore, table/column names became case
290 * sensitive.
291 *
292 * Note that neither escape nor prepared query can protect LIKE query,
293 * JSON, Array, Regex, etc. These parameters should be handled
294 * according to their contexts. i.e. Escape/validate values.
295 *
296 * @param resource $connection PostgreSQL database connection resource.
297 * @param string $table_name Name of the table from which to delete rows.
298 * @param array $assoc_array An array whose keys are field names in the table table_name,
299 * and whose values are the values of those fields that are to be deleted.
300 * @param int $options Any number of PGSQL_CONV_FORCE_NULL,
301 * PGSQL_DML_NO_CONV,
302 * PGSQL_DML_ESCAPE,
303 * PGSQL_DML_EXEC,
304 * PGSQL_DML_ASYNC or
305 * PGSQL_DML_STRING combined. If PGSQL_DML_STRING is part of the
306 * options then query string is returned. When PGSQL_DML_NO_CONV
307 * or PGSQL_DML_ESCAPE is set, it does not call pg_convert internally.
308 * @return mixed Returns TRUE on success. Returns string if PGSQL_DML_STRING is passed
309 * via options.
310 * @throws PgsqlException
311 *
312 */
313 function pg_delete($connection, string $table_name, array $assoc_array, int $options = \PGSQL_DML_EXEC)
314 {
315 error_clear_last();
316 $result = \pg_delete($connection, $table_name, $assoc_array, $options);
317 if ($result === \false) {
318 throw PgsqlException::createFromPhpError();
319 }
320 return $result;
321 }
322 /**
323 * pg_end_copy syncs the PostgreSQL frontend
324 * (usually a web server process) with the PostgreSQL server after
325 * doing a copy operation performed by
326 * pg_put_line. pg_end_copy
327 * must be issued, otherwise the PostgreSQL server may get out of
328 * sync with the frontend and will report an error.
329 *
330 * @param resource $connection PostgreSQL database connection resource. When
331 * connection is not present, the default connection
332 * is used. The default connection is the last connection made by
333 * pg_connect or pg_pconnect.
334 * @throws PgsqlException
335 *
336 */
337 function pg_end_copy($connection = null): void
338 {
339 error_clear_last();
340 if ($connection !== null) {
341 $result = \pg_end_copy($connection);
342 } else {
343 $result = \pg_end_copy();
344 }
345 if ($result === \false) {
346 throw PgsqlException::createFromPhpError();
347 }
348 }
349 /**
350 * Sends a request to execute a prepared statement with given parameters, and
351 * waits for the result.
352 *
353 * pg_execute is like pg_query_params,
354 * but the command to be executed is
355 * specified by naming a previously-prepared statement, instead of giving a
356 * query string. This feature allows commands that will be used repeatedly to
357 * be parsed and planned just once, rather than each time they are executed.
358 * The statement must have been prepared previously in the current session.
359 * pg_execute is supported only against PostgreSQL 7.4 or
360 * higher connections; it will fail when using earlier versions.
361 *
362 * The parameters are identical to pg_query_params, except that the name of a
363 * prepared statement is given instead of a query string.
364 *
365 * @param resource $connection PostgreSQL database connection resource. When
366 * connection is not present, the default connection
367 * is used. The default connection is the last connection made by
368 * pg_connect or pg_pconnect.
369 * @param string $stmtname The name of the prepared statement to execute. if
370 * "" is specified, then the unnamed statement is executed. The name must have
371 * been previously prepared using pg_prepare,
372 * pg_send_prepare or a PREPARE SQL
373 * command.
374 * @param array $params An array of parameter values to substitute for the $1, $2, etc. placeholders
375 * in the original prepared query string. The number of elements in the array
376 * must match the number of placeholders.
377 *
378 * Elements are converted to strings by calling this function.
379 * @return resource A query result resource on success.
380 * @throws PgsqlException
381 *
382 */
383 function pg_execute($connection = null, string $stmtname = null, array $params = null)
384 {
385 error_clear_last();
386 if ($params !== null) {
387 $result = \pg_execute($connection, $stmtname, $params);
388 } elseif ($stmtname !== null) {
389 $result = \pg_execute($connection, $stmtname);
390 } elseif ($connection !== null) {
391 $result = \pg_execute($connection);
392 } else {
393 $result = \pg_execute();
394 }
395 if ($result === \false) {
396 throw PgsqlException::createFromPhpError();
397 }
398 return $result;
399 }
400 /**
401 * pg_field_name returns the name of the field
402 * occupying the given field_number in the
403 * given PostgreSQL result resource. Field
404 * numbering starts from 0.
405 *
406 * @param resource $result PostgreSQL query result resource, returned by pg_query,
407 * pg_query_params or pg_execute
408 * (among others).
409 * @param int $field_number Field number, starting from 0.
410 * @return string The field name.
411 * @throws PgsqlException
412 *
413 */
414 function pg_field_name($result, int $field_number): string
415 {
416 error_clear_last();
417 $result = \pg_field_name($result, $field_number);
418 if ($result === \false) {
419 throw PgsqlException::createFromPhpError();
420 }
421 return $result;
422 }
423 /**
424 * pg_field_table returns the name of the table that field
425 * belongs to, or the table's oid if oid_only is TRUE.
426 *
427 * @param resource $result PostgreSQL query result resource, returned by pg_query,
428 * pg_query_params or pg_execute
429 * (among others).
430 * @param int $field_number Field number, starting from 0.
431 * @param bool $oid_only By default the tables name that field belongs to is returned but
432 * if oid_only is set to TRUE, then the
433 * oid will instead be returned.
434 * @return mixed On success either the fields table name or oid. Or, FALSE on failure.
435 * @throws PgsqlException
436 *
437 */
438 function pg_field_table($result, int $field_number, bool $oid_only = \false)
439 {
440 error_clear_last();
441 $result = \pg_field_table($result, $field_number, $oid_only);
442 if ($result === \false) {
443 throw PgsqlException::createFromPhpError();
444 }
445 return $result;
446 }
447 /**
448 * pg_field_type returns a string containing the
449 * base type name of the given field_number in the
450 * given PostgreSQL result resource.
451 *
452 * @param resource $result PostgreSQL query result resource, returned by pg_query,
453 * pg_query_params or pg_execute
454 * (among others).
455 * @param int $field_number Field number, starting from 0.
456 * @return string A string containing the base name of the field's type.
457 * @throws PgsqlException
458 *
459 */
460 function pg_field_type($result, int $field_number): string
461 {
462 error_clear_last();
463 $result = \pg_field_type($result, $field_number);
464 if ($result === \false) {
465 throw PgsqlException::createFromPhpError();
466 }
467 return $result;
468 }
469 /**
470 * pg_flush flushes any outbound query data waiting to be
471 * sent on the connection.
472 *
473 * @param resource $connection PostgreSQL database connection resource.
474 * @return mixed Returns TRUE if the flush was successful or no data was waiting to be
475 * flushed, 0 if part of the pending data was flushed but
476 * more remains.
477 * @throws PgsqlException
478 *
479 */
480 function pg_flush($connection)
481 {
482 error_clear_last();
483 $result = \pg_flush($connection);
484 if ($result === \false) {
485 throw PgsqlException::createFromPhpError();
486 }
487 return $result;
488 }
489 /**
490 * pg_free_result frees the memory and data associated with the
491 * specified PostgreSQL query result resource.
492 *
493 * This function need only be called if memory
494 * consumption during script execution is a problem. Otherwise, all result memory will
495 * be automatically freed when the script ends.
496 *
497 * @param resource $result PostgreSQL query result resource, returned by pg_query,
498 * pg_query_params or pg_execute
499 * (among others).
500 * @throws PgsqlException
501 *
502 */
503 function pg_free_result($result): void
504 {
505 error_clear_last();
506 $result = \pg_free_result($result);
507 if ($result === \false) {
508 throw PgsqlException::createFromPhpError();
509 }
510 }
511 /**
512 * pg_host returns the host name of the given
513 * PostgreSQL connection resource is
514 * connected to.
515 *
516 * @param resource $connection PostgreSQL database connection resource. When
517 * connection is not present, the default connection
518 * is used. The default connection is the last connection made by
519 * pg_connect or pg_pconnect.
520 * @return string A string containing the name of the host the
521 * connection is to.
522 * @throws PgsqlException
523 *
524 */
525 function pg_host($connection = null): string
526 {
527 error_clear_last();
528 if ($connection !== null) {
529 $result = \pg_host($connection);
530 } else {
531 $result = \pg_host();
532 }
533 if ($result === \false) {
534 throw PgsqlException::createFromPhpError();
535 }
536 return $result;
537 }
538 /**
539 * pg_insert inserts the values
540 * of assoc_array into the table specified
541 * by table_name. If options
542 * is specified, pg_convert is applied
543 * to assoc_array with the specified options.
544 *
545 * If options is specified,
546 * pg_convert is applied to
547 * assoc_array with the specified flags.
548 *
549 * By default pg_insert passes raw values. Values
550 * must be escaped or PGSQL_DML_ESCAPE option must be
551 * specified. PGSQL_DML_ESCAPE quotes and escapes
552 * parameters/identifiers. Therefore, table/column names became case
553 * sensitive.
554 *
555 * Note that neither escape nor prepared query can protect LIKE query,
556 * JSON, Array, Regex, etc. These parameters should be handled
557 * according to their contexts. i.e. Escape/validate values.
558 *
559 * @param resource $connection PostgreSQL database connection resource.
560 * @param string $table_name Name of the table into which to insert rows. The table table_name must at least
561 * have as many columns as assoc_array has elements.
562 * @param array $assoc_array An array whose keys are field names in the table table_name,
563 * and whose values are the values of those fields that are to be inserted.
564 * @param int $options Any number of PGSQL_CONV_OPTS,
565 * PGSQL_DML_NO_CONV,
566 * PGSQL_DML_ESCAPE,
567 * PGSQL_DML_EXEC,
568 * PGSQL_DML_ASYNC or
569 * PGSQL_DML_STRING combined. If PGSQL_DML_STRING is part of the
570 * options then query string is returned. When PGSQL_DML_NO_CONV
571 * or PGSQL_DML_ESCAPE is set, it does not call pg_convert internally.
572 * @return mixed Returns the connection resource on success. Returns string if PGSQL_DML_STRING is passed
573 * via options.
574 * @throws PgsqlException
575 *
576 */
577 function pg_insert($connection, string $table_name, array $assoc_array, int $options = \PGSQL_DML_EXEC)
578 {
579 error_clear_last();
580 $result = \pg_insert($connection, $table_name, $assoc_array, $options);
581 if ($result === \false) {
582 throw PgsqlException::createFromPhpError();
583 }
584 return $result;
585 }
586 /**
587 * pg_last_error returns the last error message
588 * for a given connection.
589 *
590 * Error messages may be overwritten by internal PostgreSQL (libpq)
591 * function calls. It may not return an appropriate error message if
592 * multiple errors occur inside a PostgreSQL module function.
593 *
594 * Use pg_result_error, pg_result_error_field,
595 * pg_result_status and
596 * pg_connection_status for better error handling.
597 *
598 * @param resource $connection PostgreSQL database connection resource. When
599 * connection is not present, the default connection
600 * is used. The default connection is the last connection made by
601 * pg_connect or pg_pconnect.
602 * @return string A string containing the last error message on the
603 * given connection.
604 * @throws PgsqlException
605 *
606 */
607 function pg_last_error($connection = null): string
608 {
609 error_clear_last();
610 if ($connection !== null) {
611 $result = \pg_last_error($connection);
612 } else {
613 $result = \pg_last_error();
614 }
615 if ($result === \false) {
616 throw PgsqlException::createFromPhpError();
617 }
618 return $result;
619 }
620 /**
621 * pg_last_notice returns the last notice
622 * message from the PostgreSQL server on the specified
623 * connection. The PostgreSQL server sends notice
624 * messages in several cases, for instance when creating a SERIAL
625 * column in a table.
626 *
627 * With pg_last_notice, you can avoid issuing useless
628 * queries by checking whether or not the notice is related to your transaction.
629 *
630 * Notice message tracking can be set to optional by setting 1 for
631 * pgsql.ignore_notice in php.ini.
632 *
633 * Notice message logging can be set to optional by setting 0 for
634 * pgsql.log_notice in php.ini.
635 * Unless pgsql.ignore_notice is set
636 * to 0, notice message cannot be logged.
637 *
638 * @param resource $connection PostgreSQL database connection resource.
639 * @param int $option One of PGSQL_NOTICE_LAST (to return last notice),
640 * PGSQL_NOTICE_ALL (to return all notices),
641 * or PGSQL_NOTICE_CLEAR (to clear notices).
642 * @return string A string containing the last notice on the
643 * given connection with
644 * PGSQL_NOTICE_LAST,
645 * an array with PGSQL_NOTICE_ALL,
646 * a boolean with PGSQL_NOTICE_CLEAR.
647 * @throws PgsqlException
648 *
649 */
650 function pg_last_notice($connection, int $option = \PGSQL_NOTICE_LAST): string
651 {
652 error_clear_last();
653 $result = \pg_last_notice($connection, $option);
654 if ($result === \false) {
655 throw PgsqlException::createFromPhpError();
656 }
657 return $result;
658 }
659 /**
660 * pg_last_oid is used to retrieve the
661 * OID assigned to an inserted row.
662 *
663 * OID field became an optional field from PostgreSQL 7.2 and will
664 * not be present by default in PostgreSQL 8.1. When the
665 * OID field is not present in a table, the programmer must use
666 * pg_result_status to check for successful
667 * insertion.
668 *
669 * To get the value of a SERIAL field in an inserted
670 * row, it is necessary to use the PostgreSQL CURRVAL
671 * function, naming the sequence whose last value is required. If the
672 * name of the sequence is unknown, the pg_get_serial_sequence
673 * PostgreSQL 8.0 function is necessary.
674 *
675 * PostgreSQL 8.1 has a function LASTVAL that returns
676 * the value of the most recently used sequence in the session. This avoids
677 * the need for naming the sequence, table or column altogether.
678 *
679 * @param resource $result PostgreSQL query result resource, returned by pg_query,
680 * pg_query_params or pg_execute
681 * (among others).
682 * @return string A string containing the OID assigned to the most recently inserted
683 * row in the specified connection or
684 * no available OID.
685 * @throws PgsqlException
686 *
687 */
688 function pg_last_oid($result): string
689 {
690 error_clear_last();
691 $result = \pg_last_oid($result);
692 if ($result === \false) {
693 throw PgsqlException::createFromPhpError();
694 }
695 return $result;
696 }
697 /**
698 * pg_lo_close closes a large
699 * object. large_object is a resource for the
700 * large object from pg_lo_open.
701 *
702 * To use the large object interface, it is necessary to
703 * enclose it within a transaction block.
704 *
705 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
706 * @throws PgsqlException
707 *
708 */
709 function pg_lo_close($large_object): void
710 {
711 error_clear_last();
712 $result = \pg_lo_close($large_object);
713 if ($result === \false) {
714 throw PgsqlException::createFromPhpError();
715 }
716 }
717 /**
718 * pg_lo_export takes a large object in a
719 * PostgreSQL database and saves its contents to a file on the local
720 * filesystem.
721 *
722 * To use the large object interface, it is necessary to
723 * enclose it within a transaction block.
724 *
725 * @param resource $connection PostgreSQL database connection resource. When
726 * connection is not present, the default connection
727 * is used. The default connection is the last connection made by
728 * pg_connect or pg_pconnect.
729 * @param int $oid The OID of the large object in the database.
730 * @param string $pathname The full path and file name of the file in which to write the
731 * large object on the client filesystem.
732 * @throws PgsqlException
733 *
734 */
735 function pg_lo_export($connection = null, int $oid = null, string $pathname = null): void
736 {
737 error_clear_last();
738 if ($pathname !== null) {
739 $result = \pg_lo_export($connection, $oid, $pathname);
740 } elseif ($oid !== null) {
741 $result = \pg_lo_export($connection, $oid);
742 } elseif ($connection !== null) {
743 $result = \pg_lo_export($connection);
744 } else {
745 $result = \pg_lo_export();
746 }
747 if ($result === \false) {
748 throw PgsqlException::createFromPhpError();
749 }
750 }
751 /**
752 * pg_lo_import creates a new large object
753 * in the database using a file on the filesystem as its data
754 * source.
755 *
756 * To use the large object interface, it is necessary to
757 * enclose it within a transaction block.
758 *
759 * @param resource $connection PostgreSQL database connection resource. When
760 * connection is not present, the default connection
761 * is used. The default connection is the last connection made by
762 * pg_connect or pg_pconnect.
763 * @param string $pathname The full path and file name of the file on the client
764 * filesystem from which to read the large object data.
765 * @param mixed $object_id If an object_id is given the function
766 * will try to create a large object with this id, else a free
767 * object id is assigned by the server. The parameter
768 * was added in PHP 5.3 and relies on functionality that first
769 * appeared in PostgreSQL 8.1.
770 * @return int The OID of the newly created large object.
771 * @throws PgsqlException
772 *
773 */
774 function pg_lo_import($connection = null, string $pathname = null, $object_id = null): int
775 {
776 error_clear_last();
777 if ($object_id !== null) {
778 $result = \pg_lo_import($connection, $pathname, $object_id);
779 } elseif ($pathname !== null) {
780 $result = \pg_lo_import($connection, $pathname);
781 } elseif ($connection !== null) {
782 $result = \pg_lo_import($connection);
783 } else {
784 $result = \pg_lo_import();
785 }
786 if ($result === \false) {
787 throw PgsqlException::createFromPhpError();
788 }
789 return $result;
790 }
791 /**
792 * pg_lo_open opens a large object in the database
793 * and returns large object resource so that it can be manipulated.
794 *
795 * To use the large object interface, it is necessary to
796 * enclose it within a transaction block.
797 *
798 * @param resource $connection PostgreSQL database connection resource. When
799 * connection is not present, the default connection
800 * is used. The default connection is the last connection made by
801 * pg_connect or pg_pconnect.
802 * @param int $oid The OID of the large object in the database.
803 * @param string $mode Can be either "r" for read-only, "w" for write only or "rw" for read and
804 * write.
805 * @return resource A large object resource.
806 * @throws PgsqlException
807 *
808 */
809 function pg_lo_open($connection, int $oid, string $mode)
810 {
811 error_clear_last();
812 $result = \pg_lo_open($connection, $oid, $mode);
813 if ($result === \false) {
814 throw PgsqlException::createFromPhpError();
815 }
816 return $result;
817 }
818 /**
819 * pg_lo_read_all reads a large object and passes
820 * it straight through to the browser after sending all pending
821 * headers. Mainly intended for sending binary data like images or
822 * sound.
823 *
824 * To use the large object interface, it is necessary to
825 * enclose it within a transaction block.
826 *
827 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
828 * @return int Number of bytes read.
829 * @throws PgsqlException
830 *
831 */
832 function pg_lo_read_all($large_object): int
833 {
834 error_clear_last();
835 $result = \pg_lo_read_all($large_object);
836 if ($result === \false) {
837 throw PgsqlException::createFromPhpError();
838 }
839 return $result;
840 }
841 /**
842 * pg_lo_read reads at most
843 * len bytes from a large object and
844 * returns it as a string.
845 *
846 * To use the large object interface, it is necessary to
847 * enclose it within a transaction block.
848 *
849 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
850 * @param int $len An optional maximum number of bytes to return.
851 * @return string A string containing len bytes from the
852 * large object.
853 * @throws PgsqlException
854 *
855 */
856 function pg_lo_read($large_object, int $len = 8192): string
857 {
858 error_clear_last();
859 $result = \pg_lo_read($large_object, $len);
860 if ($result === \false) {
861 throw PgsqlException::createFromPhpError();
862 }
863 return $result;
864 }
865 /**
866 * pg_lo_seek seeks a position within a large object
867 * resource.
868 *
869 * To use the large object interface, it is necessary to
870 * enclose it within a transaction block.
871 *
872 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
873 * @param int $offset The number of bytes to seek.
874 * @param int $whence One of the constants PGSQL_SEEK_SET (seek from object start),
875 * PGSQL_SEEK_CUR (seek from current position)
876 * or PGSQL_SEEK_END (seek from object end) .
877 * @throws PgsqlException
878 *
879 */
880 function pg_lo_seek($large_object, int $offset, int $whence = \PGSQL_SEEK_CUR): void
881 {
882 error_clear_last();
883 $result = \pg_lo_seek($large_object, $offset, $whence);
884 if ($result === \false) {
885 throw PgsqlException::createFromPhpError();
886 }
887 }
888 /**
889 * pg_lo_truncate truncates a large object
890 * resource.
891 *
892 * To use the large object interface, it is necessary to
893 * enclose it within a transaction block.
894 *
895 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
896 * @param int $size The number of bytes to truncate.
897 * @throws PgsqlException
898 *
899 */
900 function pg_lo_truncate($large_object, int $size): void
901 {
902 error_clear_last();
903 $result = \pg_lo_truncate($large_object, $size);
904 if ($result === \false) {
905 throw PgsqlException::createFromPhpError();
906 }
907 }
908 /**
909 * pg_lo_unlink deletes a large object with the
910 * oid. Returns TRUE on success.
911 *
912 * To use the large object interface, it is necessary to
913 * enclose it within a transaction block.
914 *
915 * @param resource $connection PostgreSQL database connection resource. When
916 * connection is not present, the default connection
917 * is used. The default connection is the last connection made by
918 * pg_connect or pg_pconnect.
919 * @param int $oid The OID of the large object in the database.
920 * @throws PgsqlException
921 *
922 */
923 function pg_lo_unlink($connection, int $oid): void
924 {
925 error_clear_last();
926 $result = \pg_lo_unlink($connection, $oid);
927 if ($result === \false) {
928 throw PgsqlException::createFromPhpError();
929 }
930 }
931 /**
932 * pg_lo_write writes data into a large object
933 * at the current seek position.
934 *
935 * To use the large object interface, it is necessary to
936 * enclose it within a transaction block.
937 *
938 * @param resource $large_object PostgreSQL large object (LOB) resource, returned by pg_lo_open.
939 * @param string $data The data to be written to the large object. If len is
940 * specified and is less than the length of data, only
941 * len bytes will be written.
942 * @param int $len An optional maximum number of bytes to write. Must be greater than zero
943 * and no greater than the length of data. Defaults to
944 * the length of data.
945 * @return int The number of bytes written to the large object.
946 * @throws PgsqlException
947 *
948 */
949 function pg_lo_write($large_object, string $data, int $len = null): int
950 {
951 error_clear_last();
952 if ($len !== null) {
953 $result = \pg_lo_write($large_object, $data, $len);
954 } else {
955 $result = \pg_lo_write($large_object, $data);
956 }
957 if ($result === \false) {
958 throw PgsqlException::createFromPhpError();
959 }
960 return $result;
961 }
962 /**
963 * pg_meta_data returns table definition for
964 * table_name as an array.
965 *
966 * @param resource $connection PostgreSQL database connection resource.
967 * @param string $table_name The name of the table.
968 * @param bool $extended Flag for returning extended meta data. Default to FALSE.
969 * @return array An array of the table definition.
970 * @throws PgsqlException
971 *
972 */
973 function pg_meta_data($connection, string $table_name, bool $extended = \false): array
974 {
975 error_clear_last();
976 $result = \pg_meta_data($connection, $table_name, $extended);
977 if ($result === \false) {
978 throw PgsqlException::createFromPhpError();
979 }
980 return $result;
981 }
982 /**
983 * pg_options will return a string containing
984 * the options specified on the given PostgreSQL
985 * connection resource.
986 *
987 * @param resource $connection PostgreSQL database connection resource. When
988 * connection is not present, the default connection
989 * is used. The default connection is the last connection made by
990 * pg_connect or pg_pconnect.
991 * @return string A string containing the connection
992 * options.
993 * @throws PgsqlException
994 *
995 */
996 function pg_options($connection = null): string
997 {
998 error_clear_last();
999 if ($connection !== null) {
1000 $result = \pg_options($connection);
1001 } else {
1002 $result = \pg_options();
1003 }
1004 if ($result === \false) {
1005 throw PgsqlException::createFromPhpError();
1006 }
1007 return $result;
1008 }
1009 /**
1010 * Looks up a current parameter setting of the server.
1011 *
1012 * Certain parameter values are reported by the server automatically at
1013 * connection startup or whenever their values change. pg_parameter_status can be
1014 * used to interrogate these settings. It returns the current value of a
1015 * parameter if known, or FALSE if the parameter is not known.
1016 *
1017 * Parameters reported as of PostgreSQL 8.0 include server_version,
1018 * server_encoding, client_encoding,
1019 * is_superuser, session_authorization,
1020 * DateStyle, TimeZone, and integer_datetimes.
1021 * (server_encoding, TimeZone, and
1022 * integer_datetimes were not reported by releases before 8.0.) Note that
1023 * server_version, server_encoding and integer_datetimes
1024 * cannot change after PostgreSQL startup.
1025 *
1026 * PostgreSQL 7.3 or lower servers do not report parameter settings,
1027 * pg_parameter_status
1028 * includes logic to obtain values for server_version and
1029 * client_encoding
1030 * anyway. Applications are encouraged to use pg_parameter_status rather than ad
1031 * hoc code to determine these values.
1032 *
1033 * @param resource $connection PostgreSQL database connection resource. When
1034 * connection is not present, the default connection
1035 * is used. The default connection is the last connection made by
1036 * pg_connect or pg_pconnect.
1037 * @param string $param_name Possible param_name values include server_version,
1038 * server_encoding, client_encoding,
1039 * is_superuser, session_authorization,
1040 * DateStyle, TimeZone, and
1041 * integer_datetimes. Note that this value is case-sensitive.
1042 * @return string A string containing the value of the parameter, FALSE on failure or invalid
1043 * param_name.
1044 * @throws PgsqlException
1045 *
1046 */
1047 function pg_parameter_status($connection = null, string $param_name = null): string
1048 {
1049 error_clear_last();
1050 if ($param_name !== null) {
1051 $result = \pg_parameter_status($connection, $param_name);
1052 } elseif ($connection !== null) {
1053 $result = \pg_parameter_status($connection);
1054 } else {
1055 $result = \pg_parameter_status();
1056 }
1057 if ($result === \false) {
1058 throw PgsqlException::createFromPhpError();
1059 }
1060 return $result;
1061 }
1062 /**
1063 * pg_pconnect opens a connection to a
1064 * PostgreSQL database. It returns a connection resource that is
1065 * needed by other PostgreSQL functions.
1066 *
1067 * If a second call is made to pg_pconnect with
1068 * the same connection_string as an existing connection, the
1069 * existing connection will be returned unless you pass
1070 * PGSQL_CONNECT_FORCE_NEW as
1071 * connect_type.
1072 *
1073 * To enable persistent connection, the pgsql.allow_persistent
1074 * php.ini directive must be set to "On" (which is the default).
1075 * The maximum number of persistent connection can be defined with the pgsql.max_persistent
1076 * php.ini directive (defaults to -1 for no limit). The total number
1077 * of connections can be set with the pgsql.max_links
1078 * php.ini directive.
1079 *
1080 * pg_close will not close persistent links
1081 * generated by pg_pconnect.
1082 *
1083 * @param string $connection_string The connection_string can be empty to use all default parameters, or it
1084 * can contain one or more parameter settings separated by whitespace.
1085 * Each parameter setting is in the form keyword = value. Spaces around
1086 * the equal sign are optional. To write an empty value or a value
1087 * containing spaces, surround it with single quotes, e.g., keyword =
1088 * 'a value'. Single quotes and backslashes within the value must be
1089 * escaped with a backslash, i.e., \' and \\.
1090 *
1091 * The currently recognized parameter keywords are:
1092 * host, hostaddr, port,
1093 * dbname, user,
1094 * password, connect_timeout,
1095 * options, tty (ignored), sslmode,
1096 * requiressl (deprecated in favor of sslmode), and
1097 * service. Which of these arguments exist depends
1098 * on your PostgreSQL version.
1099 * @param int $connect_type If PGSQL_CONNECT_FORCE_NEW is passed, then a new connection
1100 * is created, even if the connection_string is identical to
1101 * an existing connection.
1102 * @return resource PostgreSQL connection resource on success, FALSE on failure.
1103 * @throws PgsqlException
1104 *
1105 */
1106 function pg_pconnect(string $connection_string, int $connect_type = null)
1107 {
1108 error_clear_last();
1109 if ($connect_type !== null) {
1110 $result = \pg_pconnect($connection_string, $connect_type);
1111 } else {
1112 $result = \pg_pconnect($connection_string);
1113 }
1114 if ($result === \false) {
1115 throw PgsqlException::createFromPhpError();
1116 }
1117 return $result;
1118 }
1119 /**
1120 * pg_ping pings a database connection and tries to
1121 * reconnect it if it is broken.
1122 *
1123 * @param resource $connection PostgreSQL database connection resource. When
1124 * connection is not present, the default connection
1125 * is used. The default connection is the last connection made by
1126 * pg_connect or pg_pconnect.
1127 * @throws PgsqlException
1128 *
1129 */
1130 function pg_ping($connection = null): void
1131 {
1132 error_clear_last();
1133 if ($connection !== null) {
1134 $result = \pg_ping($connection);
1135 } else {
1136 $result = \pg_ping();
1137 }
1138 if ($result === \false) {
1139 throw PgsqlException::createFromPhpError();
1140 }
1141 }
1142 /**
1143 * pg_port returns the port number that the
1144 * given PostgreSQL connection resource is
1145 * connected to.
1146 *
1147 * @param resource $connection PostgreSQL database connection resource. When
1148 * connection is not present, the default connection
1149 * is used. The default connection is the last connection made by
1150 * pg_connect or pg_pconnect.
1151 * @return int An int containing the port number of the database
1152 * server the connection is to.
1153 * @throws PgsqlException
1154 *
1155 */
1156 function pg_port($connection = null): int
1157 {
1158 error_clear_last();
1159 if ($connection !== null) {
1160 $result = \pg_port($connection);
1161 } else {
1162 $result = \pg_port();
1163 }
1164 if ($result === \false) {
1165 throw PgsqlException::createFromPhpError();
1166 }
1167 return $result;
1168 }
1169 /**
1170 * pg_prepare creates a prepared statement for later execution with
1171 * pg_execute or pg_send_execute.
1172 * This feature allows commands that will be used repeatedly to
1173 * be parsed and planned just once, rather than each time they are executed.
1174 * pg_prepare is supported only against PostgreSQL 7.4 or
1175 * higher connections; it will fail when using earlier versions.
1176 *
1177 * The function creates a prepared statement named stmtname from the query
1178 * string, which must contain a single SQL command. stmtname may be "" to
1179 * create an unnamed statement, in which case any pre-existing unnamed
1180 * statement is automatically replaced; otherwise it is an error if the
1181 * statement name is already defined in the current session. If any parameters
1182 * are used, they are referred to in the query as $1, $2, etc.
1183 *
1184 * Prepared statements for use with pg_prepare can also be created by
1185 * executing SQL PREPARE statements. (But pg_prepare is more flexible since it
1186 * does not require parameter types to be pre-specified.) Also, although there
1187 * is no PHP function for deleting a prepared statement, the SQL DEALLOCATE
1188 * statement can be used for that purpose.
1189 *
1190 * @param resource $connection PostgreSQL database connection resource. When
1191 * connection is not present, the default connection
1192 * is used. The default connection is the last connection made by
1193 * pg_connect or pg_pconnect.
1194 * @param string $stmtname The name to give the prepared statement. Must be unique per-connection. If
1195 * "" is specified, then an unnamed statement is created, overwriting any
1196 * previously defined unnamed statement.
1197 * @param string $query The parameterized SQL statement. Must contain only a single statement.
1198 * (multiple statements separated by semi-colons are not allowed.) If any parameters
1199 * are used, they are referred to as $1, $2, etc.
1200 * @return resource A query result resource on success.
1201 * @throws PgsqlException
1202 *
1203 */
1204 function pg_prepare($connection = null, string $stmtname = null, string $query = null)
1205 {
1206 error_clear_last();
1207 if ($query !== null) {
1208 $result = \pg_prepare($connection, $stmtname, $query);
1209 } elseif ($stmtname !== null) {
1210 $result = \pg_prepare($connection, $stmtname);
1211 } elseif ($connection !== null) {
1212 $result = \pg_prepare($connection);
1213 } else {
1214 $result = \pg_prepare();
1215 }
1216 if ($result === \false) {
1217 throw PgsqlException::createFromPhpError();
1218 }
1219 return $result;
1220 }
1221 /**
1222 * pg_put_line sends a NULL-terminated string
1223 * to the PostgreSQL backend server. This is needed in conjunction
1224 * with PostgreSQL's COPY FROM command.
1225 *
1226 * COPY is a high-speed data loading interface
1227 * supported by PostgreSQL. Data is passed in without being parsed,
1228 * and in a single transaction.
1229 *
1230 * An alternative to using raw pg_put_line commands
1231 * is to use pg_copy_from. This is a far simpler
1232 * interface.
1233 *
1234 * @param resource $connection PostgreSQL database connection resource. When
1235 * connection is not present, the default connection
1236 * is used. The default connection is the last connection made by
1237 * pg_connect or pg_pconnect.
1238 * @param string $data A line of text to be sent directly to the PostgreSQL backend. A NULL
1239 * terminator is added automatically.
1240 * @throws PgsqlException
1241 *
1242 */
1243 function pg_put_line($connection = null, string $data = null): void
1244 {
1245 error_clear_last();
1246 if ($data !== null) {
1247 $result = \pg_put_line($connection, $data);
1248 } elseif ($connection !== null) {
1249 $result = \pg_put_line($connection);
1250 } else {
1251 $result = \pg_put_line();
1252 }
1253 if ($result === \false) {
1254 throw PgsqlException::createFromPhpError();
1255 }
1256 }
1257 /**
1258 * Submits a command to the server and waits for the result, with the ability
1259 * to pass parameters separately from the SQL command text.
1260 *
1261 * pg_query_params is like pg_query,
1262 * but offers additional functionality: parameter
1263 * values can be specified separately from the command string proper.
1264 * pg_query_params is supported only against PostgreSQL 7.4 or
1265 * higher connections; it will fail when using earlier versions.
1266 *
1267 * If parameters are used, they are referred to in the
1268 * query string as $1, $2, etc. The same parameter may
1269 * appear more than once in the query; the same value
1270 * will be used in that case. params specifies the
1271 * actual values of the parameters. A NULL value in this array means the
1272 * corresponding parameter is SQL NULL.
1273 *
1274 * The primary advantage of pg_query_params over pg_query
1275 * is that parameter values
1276 * may be separated from the query string, thus avoiding the need for tedious
1277 * and error-prone quoting and escaping. Unlike pg_query,
1278 * pg_query_params allows at
1279 * most one SQL command in the given string. (There can be semicolons in it,
1280 * but not more than one nonempty command.)
1281 *
1282 * @param resource $connection PostgreSQL database connection resource. When
1283 * connection is not present, the default connection
1284 * is used. The default connection is the last connection made by
1285 * pg_connect or pg_pconnect.
1286 * @param string $query The parameterized SQL statement. Must contain only a single statement.
1287 * (multiple statements separated by semi-colons are not allowed.) If any parameters
1288 * are used, they are referred to as $1, $2, etc.
1289 *
1290 * User-supplied values should always be passed as parameters, not
1291 * interpolated into the query string, where they form possible
1292 * SQL injection
1293 * attack vectors and introduce bugs when handling data containing quotes.
1294 * If for some reason you cannot use a parameter, ensure that interpolated
1295 * values are properly escaped.
1296 * @param array $params An array of parameter values to substitute for the $1, $2, etc. placeholders
1297 * in the original prepared query string. The number of elements in the array
1298 * must match the number of placeholders.
1299 *
1300 * Values intended for bytea fields are not supported as
1301 * parameters. Use pg_escape_bytea instead, or use the
1302 * large object functions.
1303 * @return resource A query result resource on success.
1304 * @throws PgsqlException
1305 *
1306 */
1307 function pg_query_params($connection = null, string $query = null, array $params = null)
1308 {
1309 error_clear_last();
1310 if ($params !== null) {
1311 $result = \pg_query_params($connection, $query, $params);
1312 } elseif ($query !== null) {
1313 $result = \pg_query_params($connection, $query);
1314 } elseif ($connection !== null) {
1315 $result = \pg_query_params($connection);
1316 } else {
1317 $result = \pg_query_params();
1318 }
1319 if ($result === \false) {
1320 throw PgsqlException::createFromPhpError();
1321 }
1322 return $result;
1323 }
1324 /**
1325 * pg_query executes the query
1326 * on the specified database connection.
1327 * pg_query_params should be preferred
1328 * in most cases.
1329 *
1330 * If an error occurs, and FALSE is returned, details of the error can
1331 * be retrieved using the pg_last_error
1332 * function if the connection is valid.
1333 *
1334 *
1335 *
1336 * Although connection can be omitted, it
1337 * is not recommended, since it can be the cause of hard to find
1338 * bugs in scripts.
1339 *
1340 *
1341 *
1342 * @param resource $connection PostgreSQL database connection resource. When
1343 * connection is not present, the default connection
1344 * is used. The default connection is the last connection made by
1345 * pg_connect or pg_pconnect.
1346 * @param string $query The SQL statement or statements to be executed. When multiple statements are passed to the function,
1347 * they are automatically executed as one transaction, unless there are explicit BEGIN/COMMIT commands
1348 * included in the query string. However, using multiple transactions in one function call is not recommended.
1349 *
1350 * String interpolation of user-supplied data is extremely dangerous and is
1351 * likely to lead to SQL
1352 * injection vulnerabilities. In most cases
1353 * pg_query_params should be preferred, passing
1354 * user-supplied values as parameters rather than substituting them into
1355 * the query string.
1356 *
1357 * Any user-supplied data substituted directly into a query string should
1358 * be properly escaped.
1359 * @return resource A query result resource on success.
1360 * @throws PgsqlException
1361 *
1362 */
1363 function pg_query($connection = null, string $query = null)
1364 {
1365 error_clear_last();
1366 if ($query !== null) {
1367 $result = \pg_query($connection, $query);
1368 } elseif ($connection !== null) {
1369 $result = \pg_query($connection);
1370 } else {
1371 $result = \pg_query();
1372 }
1373 if ($result === \false) {
1374 throw PgsqlException::createFromPhpError();
1375 }
1376 return $result;
1377 }
1378 /**
1379 * pg_result_error_field returns one of the detailed error message
1380 * fields associated with result resource. It is only available
1381 * against a PostgreSQL 7.4 or above server. The error field is specified by
1382 * the fieldcode.
1383 *
1384 * Because pg_query and pg_query_params return FALSE if the query fails,
1385 * you must use pg_send_query and
1386 * pg_get_result to get the result handle.
1387 *
1388 * If you need to get additional error information from failed pg_query queries,
1389 * use pg_set_error_verbosity and pg_last_error
1390 * and then parse the result.
1391 *
1392 * @param resource $result A PostgreSQL query result resource from a previously executed
1393 * statement.
1394 * @param int $fieldcode Possible fieldcode values are: PGSQL_DIAG_SEVERITY,
1395 * PGSQL_DIAG_SQLSTATE, PGSQL_DIAG_MESSAGE_PRIMARY,
1396 * PGSQL_DIAG_MESSAGE_DETAIL,
1397 * PGSQL_DIAG_MESSAGE_HINT, PGSQL_DIAG_STATEMENT_POSITION,
1398 * PGSQL_DIAG_INTERNAL_POSITION (PostgreSQL 8.0+ only),
1399 * PGSQL_DIAG_INTERNAL_QUERY (PostgreSQL 8.0+ only),
1400 * PGSQL_DIAG_CONTEXT, PGSQL_DIAG_SOURCE_FILE,
1401 * PGSQL_DIAG_SOURCE_LINE or
1402 * PGSQL_DIAG_SOURCE_FUNCTION.
1403 * @return string|null A string containing the contents of the error field, NULL if the field does not exist.
1404 * @throws PgsqlException
1405 *
1406 */
1407 function pg_result_error_field($result, int $fieldcode): ?string
1408 {
1409 error_clear_last();
1410 $result = \pg_result_error_field($result, $fieldcode);
1411 if ($result === \false) {
1412 throw PgsqlException::createFromPhpError();
1413 }
1414 return $result;
1415 }
1416 /**
1417 * pg_result_seek sets the internal row offset in
1418 * a result resource.
1419 *
1420 * @param resource $result PostgreSQL query result resource, returned by pg_query,
1421 * pg_query_params or pg_execute
1422 * (among others).
1423 * @param int $offset Row to move the internal offset to in the result resource.
1424 * Rows are numbered starting from zero.
1425 * @throws PgsqlException
1426 *
1427 */
1428 function pg_result_seek($result, int $offset): void
1429 {
1430 error_clear_last();
1431 $result = \pg_result_seek($result, $offset);
1432 if ($result === \false) {
1433 throw PgsqlException::createFromPhpError();
1434 }
1435 }
1436 /**
1437 * pg_select selects records specified by
1438 * assoc_array which has
1439 * field=&gt;value. For a successful query, it returns an
1440 * array containing all records and fields that match the condition
1441 * specified by assoc_array.
1442 *
1443 * If options is specified,
1444 * pg_convert is applied to
1445 * assoc_array with the specified flags.
1446 *
1447 * By default pg_select passes raw values. Values
1448 * must be escaped or PGSQL_DML_ESCAPE option must be
1449 * specified. PGSQL_DML_ESCAPE quotes and escapes
1450 * parameters/identifiers. Therefore, table/column names became case
1451 * sensitive.
1452 *
1453 * Note that neither escape nor prepared query can protect LIKE query,
1454 * JSON, Array, Regex, etc. These parameters should be handled
1455 * according to their contexts. i.e. Escape/validate values.
1456 *
1457 * @param resource $connection PostgreSQL database connection resource.
1458 * @param string $table_name Name of the table from which to select rows.
1459 * @param array $assoc_array An array whose keys are field names in the table table_name,
1460 * and whose values are the conditions that a row must meet to be retrieved.
1461 * @param int $options Any number of PGSQL_CONV_FORCE_NULL,
1462 * PGSQL_DML_NO_CONV,
1463 * PGSQL_DML_ESCAPE,
1464 * PGSQL_DML_EXEC,
1465 * PGSQL_DML_ASYNC or
1466 * PGSQL_DML_STRING combined. If PGSQL_DML_STRING is part of the
1467 * options then query string is returned. When PGSQL_DML_NO_CONV
1468 * or PGSQL_DML_ESCAPE is set, it does not call pg_convert internally.
1469 * @param int $result_type
1470 * @return mixed Returns TRUE on success. Returns string if PGSQL_DML_STRING is passed
1471 * via options.
1472 * @throws PgsqlException
1473 *
1474 */
1475 function pg_select($connection, string $table_name, array $assoc_array, int $options = \PGSQL_DML_EXEC, int $result_type = \PGSQL_ASSOC)
1476 {
1477 error_clear_last();
1478 $result = \pg_select($connection, $table_name, $assoc_array, $options, $result_type);
1479 if ($result === \false) {
1480 throw PgsqlException::createFromPhpError();
1481 }
1482 return $result;
1483 }
1484 /**
1485 * Sends a request to execute a prepared statement with given parameters,
1486 * without waiting for the result(s).
1487 *
1488 * This is similar to pg_send_query_params, but the command to be executed is specified
1489 * by naming a previously-prepared statement, instead of giving a query string. The
1490 * function's parameters are handled identically to pg_execute.
1491 * Like pg_execute, it will not work on pre-7.4 versions of
1492 * PostgreSQL.
1493 *
1494 * @param resource $connection PostgreSQL database connection resource. When
1495 * connection is not present, the default connection
1496 * is used. The default connection is the last connection made by
1497 * pg_connect or pg_pconnect.
1498 * @param string $stmtname The name of the prepared statement to execute. if
1499 * "" is specified, then the unnamed statement is executed. The name must have
1500 * been previously prepared using pg_prepare,
1501 * pg_send_prepare or a PREPARE SQL
1502 * command.
1503 * @param array $params An array of parameter values to substitute for the $1, $2, etc. placeholders
1504 * in the original prepared query string. The number of elements in the array
1505 * must match the number of placeholders.
1506 * @throws PgsqlException
1507 *
1508 */
1509 function pg_send_execute($connection, string $stmtname, array $params): void
1510 {
1511 error_clear_last();
1512 $result = \pg_send_execute($connection, $stmtname, $params);
1513 if ($result === \false) {
1514 throw PgsqlException::createFromPhpError();
1515 }
1516 }
1517 /**
1518 * Sends a request to create a prepared statement with the given parameters,
1519 * without waiting for completion.
1520 *
1521 * This is an asynchronous version of pg_prepare: it returns TRUE if it was able to
1522 * dispatch the request, and FALSE if not. After a successful call, call
1523 * pg_get_result to determine whether the server successfully created the
1524 * prepared statement. The function's parameters are handled identically to
1525 * pg_prepare. Like pg_prepare, it will not work
1526 * on pre-7.4 versions of PostgreSQL.
1527 *
1528 * @param resource $connection PostgreSQL database connection resource. When
1529 * connection is not present, the default connection
1530 * is used. The default connection is the last connection made by
1531 * pg_connect or pg_pconnect.
1532 * @param string $stmtname The name to give the prepared statement. Must be unique per-connection. If
1533 * "" is specified, then an unnamed statement is created, overwriting any
1534 * previously defined unnamed statement.
1535 * @param string $query The parameterized SQL statement. Must contain only a single statement.
1536 * (multiple statements separated by semi-colons are not allowed.) If any parameters
1537 * are used, they are referred to as $1, $2, etc.
1538 * @throws PgsqlException
1539 *
1540 */
1541 function pg_send_prepare($connection, string $stmtname, string $query): void
1542 {
1543 error_clear_last();
1544 $result = \pg_send_prepare($connection, $stmtname, $query);
1545 if ($result === \false) {
1546 throw PgsqlException::createFromPhpError();
1547 }
1548 }
1549 /**
1550 * Submits a command and separate parameters to the server without
1551 * waiting for the result(s).
1552 *
1553 * This is equivalent to pg_send_query except that query
1554 * parameters can be specified separately from the
1555 * query string. The function's parameters are
1556 * handled identically to pg_query_params. Like
1557 * pg_query_params, it will not work on pre-7.4 PostgreSQL
1558 * connections, and it allows only one command in the query string.
1559 *
1560 * @param resource $connection PostgreSQL database connection resource.
1561 * @param string $query The parameterized SQL statement. Must contain only a single statement.
1562 * (multiple statements separated by semi-colons are not allowed.) If any parameters
1563 * are used, they are referred to as $1, $2, etc.
1564 * @param array $params An array of parameter values to substitute for the $1, $2, etc. placeholders
1565 * in the original prepared query string. The number of elements in the array
1566 * must match the number of placeholders.
1567 * @throws PgsqlException
1568 *
1569 */
1570 function pg_send_query_params($connection, string $query, array $params): void
1571 {
1572 error_clear_last();
1573 $result = \pg_send_query_params($connection, $query, $params);
1574 if ($result === \false) {
1575 throw PgsqlException::createFromPhpError();
1576 }
1577 }
1578 /**
1579 * pg_send_query sends a query or queries asynchronously to the
1580 * connection. Unlike
1581 * pg_query, it can send multiple queries at once to
1582 * PostgreSQL and get the results one by one using
1583 * pg_get_result.
1584 *
1585 * Script execution is not blocked while the queries are executing. Use
1586 * pg_connection_busy to check if the connection is
1587 * busy (i.e. the query is executing). Queries may be cancelled using
1588 * pg_cancel_query.
1589 *
1590 * Although the user can send multiple queries at once, multiple queries
1591 * cannot be sent over a busy connection. If a query is sent while
1592 * the connection is busy, it waits until the last query is finished and
1593 * discards all its results.
1594 *
1595 * @param resource $connection PostgreSQL database connection resource.
1596 * @param string $query The SQL statement or statements to be executed.
1597 *
1598 * Data inside the query should be properly escaped.
1599 * @throws PgsqlException
1600 *
1601 */
1602 function pg_send_query($connection, string $query): void
1603 {
1604 error_clear_last();
1605 $result = \pg_send_query($connection, $query);
1606 if ($result === \false) {
1607 throw PgsqlException::createFromPhpError();
1608 }
1609 }
1610 /**
1611 * pg_socket returns a read only resource
1612 * corresponding to the socket underlying the given PostgreSQL connection.
1613 *
1614 * @param resource $connection PostgreSQL database connection resource.
1615 * @return resource A socket resource on success.
1616 * @throws PgsqlException
1617 *
1618 */
1619 function pg_socket($connection)
1620 {
1621 error_clear_last();
1622 $result = \pg_socket($connection);
1623 if ($result === \false) {
1624 throw PgsqlException::createFromPhpError();
1625 }
1626 return $result;
1627 }
1628 /**
1629 * pg_trace enables tracing of the PostgreSQL
1630 * frontend/backend communication to a file. To fully understand the results,
1631 * one needs to be familiar with the internals of PostgreSQL
1632 * communication protocol.
1633 *
1634 * For those who are not, it can still be
1635 * useful for tracing errors in queries sent to the server, you
1636 * could do for example grep '^To backend'
1637 * trace.log and see what queries actually were sent to the
1638 * PostgreSQL server. For more information, refer to the
1639 * PostgreSQL Documentation.
1640 *
1641 * @param string $pathname The full path and file name of the file in which to write the
1642 * trace log. Same as in fopen.
1643 * @param string $mode An optional file access mode, same as for fopen.
1644 * @param resource $connection PostgreSQL database connection resource. When
1645 * connection is not present, the default connection
1646 * is used. The default connection is the last connection made by
1647 * pg_connect or pg_pconnect.
1648 * @throws PgsqlException
1649 *
1650 */
1651 function pg_trace(string $pathname, string $mode = "w", $connection = null): void
1652 {
1653 error_clear_last();
1654 if ($connection !== null) {
1655 $result = \pg_trace($pathname, $mode, $connection);
1656 } else {
1657 $result = \pg_trace($pathname, $mode);
1658 }
1659 if ($result === \false) {
1660 throw PgsqlException::createFromPhpError();
1661 }
1662 }
1663 /**
1664 * pg_tty returns the TTY name that server
1665 * side debugging output is sent to on the given PostgreSQL
1666 * connection resource.
1667 *
1668 * @param resource $connection PostgreSQL database connection resource. When
1669 * connection is not present, the default connection
1670 * is used. The default connection is the last connection made by
1671 * pg_connect or pg_pconnect.
1672 * @return string A string containing the debug TTY of
1673 * the connection.
1674 * @throws PgsqlException
1675 *
1676 */
1677 function pg_tty($connection = null): string
1678 {
1679 error_clear_last();
1680 if ($connection !== null) {
1681 $result = \pg_tty($connection);
1682 } else {
1683 $result = \pg_tty();
1684 }
1685 if ($result === \false) {
1686 throw PgsqlException::createFromPhpError();
1687 }
1688 return $result;
1689 }
1690 /**
1691 * pg_update updates records that matches
1692 * condition with data. If
1693 * options is specified,
1694 * pg_convert is applied to
1695 * data with specified options.
1696 *
1697 * pg_update updates records specified by
1698 * assoc_array which has
1699 * field=&gt;value.
1700 *
1701 * If options is specified,
1702 * pg_convert is applied to
1703 * assoc_array with the specified flags.
1704 *
1705 * By default pg_update passes raw values. Values
1706 * must be escaped or PGSQL_DML_ESCAPE option must be
1707 * specified. PGSQL_DML_ESCAPE quotes and escapes
1708 * parameters/identifiers. Therefore, table/column names became case
1709 * sensitive.
1710 *
1711 * Note that neither escape nor prepared query can protect LIKE query,
1712 * JSON, Array, Regex, etc. These parameters should be handled
1713 * according to their contexts. i.e. Escape/validate values.
1714 *
1715 * @param resource $connection PostgreSQL database connection resource.
1716 * @param string $table_name Name of the table into which to update rows.
1717 * @param array $data An array whose keys are field names in the table table_name,
1718 * and whose values are what matched rows are to be updated to.
1719 * @param array $condition An array whose keys are field names in the table table_name,
1720 * and whose values are the conditions that a row must meet to be updated.
1721 * @param int $options Any number of PGSQL_CONV_FORCE_NULL,
1722 * PGSQL_DML_NO_CONV,
1723 * PGSQL_DML_ESCAPE,
1724 * PGSQL_DML_EXEC,
1725 * PGSQL_DML_ASYNC or
1726 * PGSQL_DML_STRING combined. If PGSQL_DML_STRING is part of the
1727 * options then query string is returned. When PGSQL_DML_NO_CONV
1728 * or PGSQL_DML_ESCAPE is set, it does not call pg_convert internally.
1729 * @return mixed Returns TRUE on success. Returns string if PGSQL_DML_STRING is passed
1730 * via options.
1731 * @throws PgsqlException
1732 *
1733 */
1734 function pg_update($connection, string $table_name, array $data, array $condition, int $options = \PGSQL_DML_EXEC)
1735 {
1736 error_clear_last();
1737 $result = \pg_update($connection, $table_name, $data, $condition, $options);
1738 if ($result === \false) {
1739 throw PgsqlException::createFromPhpError();
1740 }
1741 return $result;
1742 }
1743 /**
1744 * pg_version returns an array with the client, protocol
1745 * and server version. Protocol and server versions are only available if PHP
1746 * was compiled with PostgreSQL 7.4 or later.
1747 *
1748 * For more detailed server information, use pg_parameter_status.
1749 *
1750 * @param resource $connection PostgreSQL database connection resource. When
1751 * connection is not present, the default connection
1752 * is used. The default connection is the last connection made by
1753 * pg_connect or pg_pconnect.
1754 * @return array Returns an array with client, protocol
1755 * and server keys and values (if available) or invalid connection.
1756 * @throws PgsqlException
1757 *
1758 */
1759 function pg_version($connection = null): array
1760 {
1761 error_clear_last();
1762 if ($connection !== null) {
1763 $result = \pg_version($connection);
1764 } else {
1765 $result = \pg_version();
1766 }
1767 if ($result === \false) {
1768 throw PgsqlException::createFromPhpError();
1769 }
1770 return $result;
1771 }
1772