1--TEST--
2PostgreSQL pg_escape_bytea() functions (escape format)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("inc/skipif.inc"); ?>
7--FILE--
8<?php
9// optional functions
10
11include('inc/config.inc');
12$table_name = "table_18pg_escape_bytea_esc";
13
14$db = pg_connect($conn_str);
15pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
16
17@pg_query($db, "SET bytea_output = 'escape'");
18
19$image = file_get_contents(__DIR__ . '/php.gif');
20$esc_image = pg_escape_bytea($db, $image);
21
22pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
23$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
24$rows = pg_fetch_all($result);
25$unesc_image = pg_unescape_bytea($rows[0]['bin']);
26
27if ($unesc_image !== $image) {
28    echo "NG";
29}
30else {
31    echo "OK";
32}
33?>
34--CLEAN--
35<?php
36include('inc/config.inc');
37$table_name = "table_18pg_escape_bytea_esc";
38
39$db = pg_connect($conn_str);
40pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
41?>
42--EXPECT--
43OK
44