1--TEST--
2PostgreSQL pg_escape_bytea() functions (before connection)
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_before";
13
14$image = file_get_contents(__DIR__ . '/php.gif');
15$esc_image = pg_escape_bytea($image);
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 = 'escape'");
21
22pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, E\''.$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_before";
38
39$db = pg_connect($conn_str);
40pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
41?>
42--EXPECTF--
43Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
44OK
45