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