xref: /PHP-8.3/ext/pgsql/tests/gh13354.phpt (revision 452e008f)
1--TEST--
2GH-13354 (null-by-reference handling in pg_execute, pg_send_query_params, pg_send_execute)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("skipif.inc"); ?>
7--FILE--
8<?php
9include 'config.inc';
10
11$db = pg_connect($conn_str);
12$val = null;
13
14$query = 'SELECT $1::text IS NULL;';
15$params_null = [null];
16$params_null_by_ref = [&$val];
17
18pg_prepare($db, 'test', $query);
19
20
21// method 1, pg_execute
22$val = null;
23$res = pg_execute($db, 'test', $params_null);
24echo "pg_execute, null value: " . pg_fetch_result($res, 0, 0) . "\n";
25pg_free_result($res);
26
27$res = pg_execute($db, 'test', $params_null_by_ref);
28echo "pg_execute, null value by reference: " . pg_fetch_result($res, 0, 0) . "\n";
29pg_free_result($res);
30
31
32// method 2, pg_query_params
33$res = pg_query_params($db, $query, $params_null);
34echo "pg_query_params, null value: " . pg_fetch_result($res, 0, 0) . "\n";
35pg_free_result($res);
36
37$res = pg_query_params($db, $query, $params_null_by_ref);
38echo "pg_query_params, null value by reference: " . pg_fetch_result($res, 0, 0) . "\n";
39pg_free_result($res);
40
41
42// method 3, pg_send_query_params
43$res = pg_send_query_params($db, $query, $params_null);
44pg_consume_input($db);
45$res = pg_get_result($db);
46echo "pg_send_query_params, null value: " . pg_fetch_result($res, 0, 0) . "\n";
47pg_free_result($res);
48
49$res = pg_send_query_params($db, $query, $params_null_by_ref);
50pg_consume_input($db);
51$res = pg_get_result($db);
52echo "pg_send_query_params, null value by reference: " . pg_fetch_result($res, 0, 0) . "\n";
53pg_free_result($res);
54
55
56// method 4, pg_send_prepare, pg_send_execute
57pg_send_execute($db, 'test', $params_null);
58pg_consume_input($db);
59$res = pg_get_result($db);
60echo "pg_send_execute, null value: " . pg_fetch_result($res, 0, 0) . "\n";
61pg_free_result($res);
62
63pg_send_execute($db, 'test', $params_null_by_ref);
64pg_consume_input($db);
65$res = pg_get_result($db);
66echo "pg_send_execute, null value by reference: " . pg_fetch_result($res, 0, 0) . "\n";
67pg_free_result($res);
68
69pg_close($db);
70
71?>
72--EXPECT--
73pg_execute, null value: t
74pg_execute, null value by reference: t
75pg_query_params, null value: t
76pg_query_params, null value by reference: t
77pg_send_query_params, null value: t
78pg_send_query_params, null value by reference: t
79pg_send_execute, null value: t
80pg_send_execute, null value by reference: t
81