1--TEST--
2PostgreSQL pg_escape_bytea() functions (hex format)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("skipif.inc");
8skip_bytea_not_hex();
9?>
10--FILE--
11<?php
12// optional functions
13
14include('config.inc');
15
16$db = pg_connect($conn_str);
17@pg_query($db, "SET bytea_output = 'hex'");
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--EXPECT--
35OK
36