1--TEST--
2PostgreSQL pg_escape_bytea() functions (before connection)
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php
7// optional functions
8
9include('config.inc');
10
11$image = file_get_contents(__DIR__ . '/php.gif');
12$esc_image = pg_escape_bytea($image);
13
14$db = pg_connect($conn_str);
15@pg_query($db, "SET bytea_output = 'escape'");
16
17pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, E\''.$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