1--TEST--
2PostgreSQL pg_escape_bytea() functions (escape format)
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php
7// optional functions
8
9include('config.inc');
10
11$db = pg_connect($conn_str);
12@pg_query($db, "SET bytea_output = 'escape'");
13
14$image = file_get_contents(__DIR__ . '/php.gif');
15$esc_image = pg_escape_bytea($image);
16
17pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
18$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
19$rows = pg_fetch_all($result);
20$unesc_image = pg_unescape_bytea($rows[0]['bin']);
21
22if ($unesc_image !== $image) {
23    echo "NG";
24}
25else {
26    echo "OK";
27}
28?>
29--EXPECT--
30OK
31